合并和颜色样式不适用于Apache POI Excel 2003格式

在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版本的这些单元格。

有什么build议么!

 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); 

这可能对初学者有帮助。 样式的创build不能在循环中完成。