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

查看:30
本文介绍了合并和颜色样式不适用于 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天全站免登陆