package com.ste.qr.stats.export;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.AbstractCellWriteHandler;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import org.apache.poi.ss.usermodel.*;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.List;
//设置表头、内容的行高
public class CustomCellWriteHandler implements CellWriteHandler {
private static NumberFormat nf = NumberFormat.getPercentInstance();
@Override
public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
row.setHeight((short) 288);
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
int cellIndex = cell.getColumnIndex();
int columnWidth = 25;
// WriteFont writeFont = new WriteFont();
Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
CellStyle cellStyle = CellStyleUtil.cellStyle(workbook);
writeSheetHolder.getSheet().setColumnWidth(cellIndex, columnWidth * 150);
// 标题颜色
if (cell.getRowIndex() == 3) {
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex());
}
if (cell.getRowIndex() > 1 && cell.getRowIndex() < 4 && cell.getColumnIndex() > 23 && cell.getColumnIndex() < 26) {
cellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
}
if (cell.getRowIndex() > 0 && cell.getRowIndex() < 4 && cell.getColumnIndex() > 25 && cell.getColumnIndex() < 33) {
cellStyle.setFillForegroundColor(IndexedColors.ROSE.getIndex());
}
//// 负数字体颜色
// if (cell.getRowIndex() > 3 && cell.getColumnIndex() < 36) {
// try {
// if (nf.parse(cell.getStringCellValue()).doubleValue() < 0) {
// writeFont.setColor(IndexedColors.RED.getIndex());
// cellStyle.setFont(workbook.createFont());
// cell.setCellStyle(cellStyle);
// }
// } catch (ParseException e) {
// throw new RuntimeException(e);
// }
// }
//// 部组名行背景颜色设置
// if (cell.getColumnIndex() == 1) {
// if (nf.parse(cell.getStringCellValue().equals())){
//
// }
// }
}
}
问题描述
重写方法后,用registerwritehandler运用,但仍显示 0 usages 没有被运用
1条答案
按热度按时间hmmo2u0o1#