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

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

问题描述

在Apache POI中,我已经为某些单元格应用了某些样式并合并了这些单元格。当我在2010年或2007年开放时,它的作品很好,但在2003年的格式风格已经消失了。每次保存2003 Excel文件之前,它会打开兼容性检查对话框。

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.

请参考屏幕截图。

以下是示例代码:

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

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.

任何建议!

推荐答案

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天全站免登陆