首页 文章

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

提问于
浏览
2

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

请参考屏幕截图 .

enter image description here

以下是示例代码:

.........
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版本的那些单元格中应用颜色和合并 .

有什么建议!

1 回答

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

    它可能有助于乞讨者 . 样式的创建不能在循环中完成 .

相关问题