0
public class AppStarter {
public static void main(String[] args) {
SparkUserExcelRequest request = new SparkUserExcelRequest();
request.setNickname("test");
String writePathName = "/Users/dolphin/source/dabai/microservice/soa-zhuolian-org/";
String fullPathName = writePathName + "a.xlsx";
if (!new File(writePathName).exists()) {
new File(writePathName).mkdirs();
}
ExcelWriterBuilder writerBuilder = EasyExcel.write(fullPathName, SparkUserExcelRequest.class);
writerBuilder.excelType(ExcelTypeEnum.XLSX);
writerBuilder.registerWriteHandler(new CellStyleWriteHandler());
ExcelWriter writer = writerBuilder.build();
WriteSheet writeSheet = new WriteSheet();
writeSheet.setSheetName("mark");
writer.write(Arrays.asList(request), writeSheet);
writer.finish();
}
}
public class CellStyleWriteHandler extends AbstractCellStyleStrategy {
@Override
protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
Workbook workbook = cell.getSheet().getWorkbook();
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
cell.setCellStyle(cellStyle);
}
}
@Data
@ExcelIgnoreUnannotated
public class SparkUserExcelRequest implements Serializable {
@ExcelProperty("姓名")
private String nickname;
}
异常提示?
https://stackoverflow.com/questions/71111037/why-the-easy-excel-set-cell-style-did-not-work