Excel对您可以拥有的不同单元格样式的数量有限制,而且出奇的低。对于使用POI的新手来说,一个常见问题是他们跳过关于单元格样式的工作簿范围,而是他们为每个单元格创建一种单元格样式。这很快促使他们在Excel中的限制...
你在哪里代码以前可能看起来像
Sheet s = wb.createSheet();
for (int rn=0; rn<=10; rn++) {
Row r = s.createRow(rn);
for (int cn=0; cn<=4; cn++) {
Cell c = r.createCell(c);
c.setCellValue(getMyCellValue(rn,cn));
CellStyle cs = wb.createCellStyle();
cs.setBold(true);
if (cn == 2) {
cs.setDataFormat(DataFormat.getFormat(yyyy/mm/dd));
}
c.setCellStyle(cs);
}
}
你,而不是要拉你的单元格样式创造出来开始,像
CellStyle bold = wb.createCellStyle();
bold.setBold(true);
CellStyle boldDate = wb.createCellStyle();
boldDate.setBold(true);
boldDate.setDataFormat(DataFormat.getFormat(yyyy/mm/dd));
Sheet s = wb.createSheet();
for (int rn=0; rn<=10; rn++) {
Row r = s.createRow(rn);
for (int cn=0; cn<=4; cn++) {
Cell c = r.createCell(c);
c.setCellValue(getMyCellValue(rn,cn));
CellStyle cs = bold;
if (cn == 2) {
cs = boldDate;
}
c.setCellStyle(cs);
}
}
你能告诉我们代码吗? – cporte 2012-07-13 19:15:30
您是否可能为每个单元生成一种单元格格式?单元格格式为工作簿范围,应该重新使用... – Gagravarr 2012-07-13 20:38:17