Merge and Color style not applying in Apache POI excel 2003 format

牧云@^-^@ 提交于 2019-12-24 04:42:06

问题


In Apache POI, I have apply some styles for some cells and merged those cells. When I open in 2010 or 2007 its works fine, but in 2003 the formatting style is gone. It thorws the compatibility check dialog before saving the 2003 excel file each time.

Please refer the screen shot.

Below is the sample code :

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

merging the cells

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

I removed the merge code, I am getting color in 2003. The style gets applied. But I want both color and merge to be applied in those cells for 2003 version.

Any suggestions!


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

it may help for beginers. creation of styles must not be done in loops.



来源:https://stackoverflow.com/questions/11952339/merge-and-color-style-not-applying-in-apache-poi-excel-2003-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!