Java 如何设置被导出excel单元格的样式?例如背景色,大小什么的?(eclipse的java文件怎么保存到桌面)
admin
2023-05-15 11:16:47


使用 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]);// 给单元格赋值
}

不知道能,看懂不,如果有不清楚的私聊 导出时,会 用到Java的excel到处类 该类是有单独的jar包支持,该Jar包中有实现好的类取做很多事情,你在导出的地方New一个导出类的对象,该对象下应该有设置属性的地方 你试试吧 使用 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]);// 给单元格赋值
}

不知道能,看懂不,如果有不清楚的私聊

相关内容

热门资讯

拼多多上的手机是正品吗?怎么买... 拼多多平台上面的产品各式各样,有食品,有服饰,有手机电脑等等,有一些朋友买一些生活用品是比较放心的,...