POI 使用XSSF导出Excel自定义单元格颜色为什么始终是黑色的?代码如下
XSSFCellStylestyle=wb.createCellStyle();;style.setFillForegroundColor(newXSSFColor(ne...
XSSFCellStyle style = wb.createCellStyle();;
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(231,230,230),new DefaultIndexedColorMap()));
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); 展开
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(231,230,230),new DefaultIndexedColorMap()));
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); 展开
1个回答
展开全部
使用 poi ,具体实现
HSSFCellStyle style = null;
// 创建表头style
HSSFCellStyle cellStyleTitle = workbook.createCellStyle();
cellStyleTitle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充单元格
cellStyleTitle.setFillForegroundColor(HSSFColor.YELLOW.index);
cellStyleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// //居中显示
HSSFRow titleRow = sheet.createRow(0);
for (int i = 0; i < titles.length; i++) {
HSSFCell cell = titleRow.createCell(i);
// cell.setCellStyle(createCellColorStyle(workbook));
cell.setCellStyle(cellStyleTitle);
cell.setCellValue(titles[i]);// 给单元格赋值
}
HSSFCellStyle style = null;
// 创建表头style
HSSFCellStyle cellStyleTitle = workbook.createCellStyle();
cellStyleTitle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 填充单元格
cellStyleTitle.setFillForegroundColor(HSSFColor.YELLOW.index);
cellStyleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// //居中显示
HSSFRow titleRow = sheet.createRow(0);
for (int i = 0; i < titles.length; i++) {
HSSFCell cell = titleRow.createCell(i);
// cell.setCellStyle(createCellColorStyle(workbook));
cell.setCellStyle(cellStyleTitle);
cell.setCellValue(titles[i]);// 给单元格赋值
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询