【问题标题】:Merge and Color style not applying in Apache POI excel 2003 format合并和颜色样式不适用于 Apache POI excel 2003 格式
【发布时间】:2012-08-10 17:55:37
【问题描述】:

在 Apache POI 中,我为某些单元格应用了一些样式并合并了这些单元格。当我在 2010 年或 2007 年打开时,它的工作正常,但在 2003 年,格式样式消失了。它会在每次保存 2003 excel 文件之前打开兼容性检查对话框。

请参考屏幕截图。

下面是示例代码:

.........
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
.........
cell.setCellStyle(style);

合并单元格

CellRangeAddress cr = new CellRangeAddress(10, 10, 18,23);
sheet.addMergedRegion(cr);

我删除了合并代码,我在 2003 年得到了颜色。样式被应用了。但我希望在 2003 版的这些单元格中同时应用颜色和合并。

任何建议!

【问题讨论】:

  • 在 Excel 中也是一样的。第一个单元格的单元格样式设置为第二个单元格的默认样式。可以先合并单元格再设置颜色样式吗?
  • 我已经交换了合并和应用颜色代码但不工作。

标签: java excel excel-2007 apache-poi excel-2010


【解决方案1】:
int rownum = sheet.getLastRowNum()+1;
sheet.addMergedRegion(new Region(10,10,18,23));
HSSFRow row=sheet.createRow(rownum);
HSSFCell secCell=row.createCell(0);


 HSSFCellStyle cellStyle = workBook.createCellStyle();
 style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
 style.setFillPattern(CellStyle.SOLID_FOREGROUND);
 cell.setCellStyle(style);

它可能对初学者有所帮助。样式的创建不能循环进行。

【讨论】:

  • 您没有为“单元格”分配任何内容。如何为区域添加样式?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多