如 Person对象,有 name, age, sex
name、age 输出到第一行,sex输出到第二行
现在有2个Person对象,该如何操作,目前碰到 第一个Person对象sex 会被覆盖,不能显示
nr7wwzry1#
import com.alibaba.excel.write.handler.RowWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteTableHolder; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; public class CustomRowWriteHandler implements RowWriteHandler { @Override public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex, Integer relativeRowIndex, Boolean isHead) { // 在创建行之前,判断是否是 sex 字段对应的行,如果是,则创建额外一行 if (rowIndex == 1) { Sheet sheet = writeSheetHolder.getSheet(); sheet.createRow(rowIndex + 1); } } @Override public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) { // do nothing } @Override public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) { // do nothing } }
1条答案
按热度按时间nr7wwzry1#