合并和Apache的POI不适用的色彩风格Excel 2003中的格式 [英] Merge and Color style not applying in Apache POI excel 2003 format

查看:140
本文介绍了合并和Apache的POI不适用的色彩风格Excel 2003中的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Apache的POI,我已经申请了一些细胞的一些风格和合并这些细胞。当我在2010年或2007年其作品精美打开,但在2003年的格式样式已经一去不复返了。它保存了2003年的Excel每次文件之前thorws兼容性检查对话框。

请参阅屏幕截图。

下面是示例code:

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

合并单元格

 的CellRangeAddress CR =新的CellRangeAddress(10,10,18,23);
sheet.addMergedRegion(CR);

我删除合并code,我收到2003年的色彩风格被应用。但我想这两个颜色和合并的这些细胞能应​​用于2003版本。

任何建议!


解决方案

  INT的rownum = sheet.getLastRowNum()+ 1;
sheet.addMergedRegion(新区域(10,10,18,23));
HSSFRow行= 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(样式);

这可能帮助beginers。风格创作不能在循环中完成。

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!

解决方案

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.

这篇关于合并和Apache的POI不适用的色彩风格Excel 2003中的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆