easyexcel IndexedColors 64个颜色值效果预览
easyexcel
快速、简洁、解决大文件内存溢出的java处理Excel工具
项目地址:https://gitcode.com/gh_mirrors/ea/easyexcel

·
2024年6月26日
public static void main(String[] args) throws IOException {
File file = new File("./testColor.xlsx");
try(OutputStream out = new FileOutputStream(file, false);) {
ExcelWriter excelWriter = EasyExcel.write(out).inMemory(true).build();
List<List<String>> head = new ArrayList<>();
List<String> h0 = new ArrayList();
h0.add("IndexedColors的64个色值");
head.add(h0);
OnceAbsoluteMergeStrategy mergeHead = new OnceAbsoluteMergeStrategy(0,0,0,3);
//数据
List<List<WriteCellData<String>>> data = new ArrayList<>();
// short index = IndexedColors.BLUE.getIndex();// IndexedColors 颜色枚举
for (int i = 0; i < 16; i++) {
List<WriteCellData<String>> row = new ArrayList<>(4);
for (int j = 0; j < 4; j++) {
short val = (short) (i * 4 + j + 1);
String label = String.valueOf(val);
// 创建单元格 值和类型
WriteCellData<String> cell = new WriteCellData(label);
cell.setType(CellDataTypeEnum.STRING);
WriteCellStyle style = new WriteCellStyle();
style.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
style.setFillForegroundColor(val);
cell.setWriteCellStyle(style);
row.add(cell);
}
data.add(row);
}
WriteSheet sheet = EasyExcel.writerSheet(0, "色值")
.registerWriteHandler(new SimpleRowHeightStyleStrategy((short)30,(short)20))
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(15))
.registerWriteHandler(mergeHead)
.head(head)
.build();
excelWriter.write(data, sheet);
excelWriter.finish();
out.flush();
out.close();
} catch (Exception e) {
LoggerFactory.getLogger("Easy Excel").info(e.getMessage());
e.printStackTrace();
} finally {
}
}




快速、简洁、解决大文件内存溢出的java处理Excel工具
最近提交(Master分支:19 天前 )
c42183df
Bugfix 1 年前
efa7dff6 * 重新加回 `commons-io`
1 年前
更多推荐
所有评论(0)