package com.sckw.excel.easyexcel;

//import com.alibaba.excel.metadata.CellData;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;

/**
 * @author LengFaQiang
 * @version 1.0.0
 * @ClassName RowWriteHandlerImpl.java
 * @Description 设置导出excel的单元格格式为文本
 * @createTime 2022年012月021日 10:15:00
 */
public class RowWriteHandlerImpl implements CellWriteHandler {

    CellStyle cellStyle;
    @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();
        if (cellStyle == null){
            cellStyle = workbook.createCellStyle();
        }
        DataFormat dataFormat = workbook.createDataFormat();
        cellStyle.setDataFormat(dataFormat.getFormat("@"));
        cell.setCellStyle(cellStyle);
    }
}
