excel 写

EasyExcel.write(outputStream,xxxExcelModel.class).registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new ExcelWidthStyleStrategy()).sheet("xxxsheet1").doWrite(xxxList);

样式
private WriteCellStyle getHeadStyle(){
//头设置
WriteCellStyle writeCellStyle = new WriteCellStyle();
writeCellStyle.setFillBackgroundColor(IndexedColors.RED.index);
writeCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
//字体
WriteFont writeFont = new WriteFont();
writeFont.setFontHeightInPoints((short)11);
writeCellStyle.setWriteFont(writeFont);
writeCellStyle.setShrinkToFit(true);
return writeCellStyle;
}

表头字段宽度
class ExcelWidthStyleStrategy extends AbstractColumnWidthStyleStrategy{

@Override
protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> list, Cell cell, Head head, Integer integer, Boolean aBoolean) {

Sheet sheet = writeSheetHolder.getSheet();
sheet.setColumnWidth(cell.getColumnIndex(),4000);
}
}
talk is cheap. show me the code.
原文地址:https://www.cnblogs.com/yushizhang/p/15262306.html