[alibaba/easyexcel]不用注解的方式,如何将文本型改为数值型

2024-04-26 515 views
2

导出的文件有很多列都为数字,默认都是文本型,导出来后左上角有三角,怎么改为数值型,并且不是在注解里修改

回答

9

`public class TestStyleExcelHandler implements CellWriteHandler { @Override public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) {

}

@Override
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer integer, Boolean aBoolean) {
}

@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> list, Cell cell, Head head, Integer integer, Boolean isHeader) {
    Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
    CellStyle cellStyle = workbook.createCellStyle();

// HSSFDataFormat dataFormat = (HSSFDataFormat) workbook.createDataFormat(); if (!isHeader) { cellStyle.setDataFormat((short) 1); cell.setCellStyle(cellStyle); } } } ` 自定义了一个handler去转换,cellStyle.setDataFormat((short) 1); 如果不是头,就全部转换为整数,但是最后还是文本型 ,请看下是什么问题呢

6

主要提供详细代码。如果是 2.1.3的话 ,默认数字 就是数字类型了。

0

不确定你是否解决了?如果未解决,请重新打开iussue