问题
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