package com.yunzhi.marketing.excel.handler;

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 lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 * excel 转换器
 */
@Slf4j
public class CustomCellWriteHandler implements CellWriteHandler {

    @Override
    public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, int relativeRowIndex, boolean isHead) {

    }

    @Override
    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData, Cell cell, Head head, int relativeRowIndex, boolean isHead) {

//        // 这里可以对cell进行任何操作
//        log.info("第{}行，第{}列写入前拦截。", cell.getRowIndex(), cell.getColumnIndex());
//        if (isHead && cell.getColumnIndex() == 2) {
//            String currentCellValue = cell.getStringCellValue();
//            String value = "1".equals(currentCellValue) ? "男" : "0".equals(currentCellValue) ? "女" : "未知";
//            cell.setCellValue(value);
//        }
    }
}
