Java 导出Excel 设置单元格样式
// 设置字体以及单元格格式
CellStyle format = workbook.createCellStyle();
XSSFFont wfont = workbook.createFont();
wfont.setFontName("楷书");
wfont.setFontHeightInPoints((short) 12);
format.setFont(wfont);
format.setAlignment(HorizontalAlignment.LEFT);
format.setVerticalAlignment(VerticalAlignment.TOP);
// 创建表头
XSSFRow header = sheet.createRow(0);
// 第二行写入标题
for (int i = 0; i < nameList.size(); i++) {
Cell cell = header.createCell(i);
cell.setCellValue(nameList.get(i));
cell.setCellStyle(blackStyle);
}
本文介绍了在Java中使用ApachePOI库操作Excel时,如何设置单元格样式(如字体、对齐方式),以及如何创建表头和填写标题的具体步骤。
541

被折叠的 条评论
为什么被折叠?



