@Looly
感觉设置列格式有点问题。
问题描述:
导出excel模板,第一行是标题,第二行是表头标题,第三行以后就是正文。
我先设置第一行标题样式,style.getHeadCellStyle();就可以,没问题。
再设置第二行表头标题样式,style.getCellStyle();设置后,所有正文,样式也就改了。
我感觉cn.hutool.poi.excel.StyleSet;类中是不是要区分出第二行和正文来?
以下是代码实例:
//设置每列宽度 start
DataFormat format = sxssfBook.createDataFormat();
CellStyle textStyle = style.getCellStyle();
textStyle.setDataFormat(format.getFormat("@"));
for (int i = 0; i < headerrow.size(); i++) {
sheetAt0.setColumnWidth(i, 20 * 256);
//即使先设置默认列格式,也会被后面的cellStyle 覆盖正文样式
sheetAt0.setDefaultColumnStyle(i, textStyle);
}
//设置每列宽度 end
writer.merge(fieldLists.size() - 1, form_zh_name);
writer.write(rows, true);
//第二行 title行
Row row = sheetAt0.getRow(1);
CellStyle cellStyle = style.getCellStyle();
Font font2 = sxssfBook.createFont();
font2.setFontName("Courier New");
font2.setBold(true);
font2.setColor(IndexedColors.BLACK.getIndex());
font2.setFontHeight((short) (15 * 20));
cellStyle.setFont(font2);
row.getCell(0).setCellStyle(cellStyle);