问题描述
我已经使用code specied这里合并两个Excel文件
I have merged two excel files using the code specied here
该应用样式我合并单元格块
this the block applying the styles for my merging cells
if (styleMap != null)
{
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook())
{
newCell.setCellStyle(oldCell.getCellStyle());
}
else
{
int stHashCode = oldCell.getCellStyle().hashCode();
XSSFCellStyle newCellStyle = styleMap.get(stHashCode);
if (newCellStyle == null)
{
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
styleMap.put(stHashCode, newCellStyle);
}
newCell.setCellStyle(newCellStyle);
}
}
这一切都按预期工作,并生成我XSSFWorkbook顺利。
It all working as expected and going well in generating my XSSFWorkbook.
问题出发,当我尝试打开它:
Problem starting when I try to open it:
我见下文误差
和我的错误报告中包含以下
and my error report contains below
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error072840_01.xml</logFileName>
<summary>Errors were detected in file 'XYZ.xlsx'</summary>
<repairedRecords summary="Following is a list of repairs:">
<repairedRecord>Repaired Records: Format from /xl/styles.xml part (Styles)</repairedRecord>
</repairedRecords>
</recoveryLog>
在所有这些我单开了罚款,但没有风格。我知道有是要创建的款式数量限制,已经算正在创建的风格,我几乎看不到4中创建。我甚至知道这个问题是有太多的风格。
After all these my sheet opens up fine but without styles. I know there is a limitation on number of styles to be created and have counted the styles being created and I hardly see 4 created. I even know that this issue is with too many styles.
不幸的是,POI有支持优化只HSSFWorkbook()
Unfortunately, POI has support to optimise only HSSFWorkbook (Apache POI delete CellStyle from workbook)
在如何处理这一问题减轻任何帮助将是巨大的。
Any help in how to mitigate with this issue will be great.
推荐答案
好,调试POI code位以及如何被应用的样式等之后。
Well, after debugging bit of POI code and how styles are being applied and so.
做下面的问题解决了。
newCellStyle.getCoreXf().unsetBorderId();
newCellStyle.getCoreXf().unsetFillId();
这篇关于从/xl/styles.xml部分(样式)QUOT格式:修理记录; POI Excel的合并造成&QUOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!