easyexcel设置单元格格式为文本
Posted jaminye
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了easyexcel设置单元格格式为文本相关的知识,希望对你有一定的参考价值。
导出时注册registerWriteHandler(new RowWriteHandlerImpl())
/**
* @author jamin
* @date 2020/7/29 15:18
*/
public class RowWriteHandlerImpl 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) {
//设置单元格格式为文本
Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
CellStyle cellStyle = workbook.createCellStyle();
DataFormat dataFormat = workbook.createDataFormat();
cellStyle.setDataFormat(dataFormat.getFormat("@"));
cell.setCellStyle(cellStyle);
}
//加@Override会报错
public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData, 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 aBoolean) {
}
}
以上是关于easyexcel设置单元格格式为文本的主要内容,如果未能解决你的问题,请参考以下文章
如何把Excel单元格默认的格式设置为“文本” ,我的意思是下次启动格式默认为‘文本’格式
Qt 中 QTableView 中如何设置某一单元格文本的颜色值,希望能贴出代码。