码迷,mamicode.com
首页 > 其他好文 > 详细

easyexcel设置单元格格式为文本

时间:2020-07-30 01:27:37      阅读:420      评论:0      收藏:0      [点我收藏+]

标签:set   bool   integer   rri   date   oid   eth   write   单元   

导出时注册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设置单元格格式为文本

标签:set   bool   integer   rri   date   oid   eth   write   单元   

原文地址:https://www.cnblogs.com/JaminYe/p/13401439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!