关注帖子@ POI Excel Merging Causing "Repaired Records: Format from /xl/styles.xml part (Styles)"
我有两个excel文件,它们在样式和颜色方面都很好(在Microsoft Office 2010中) .
我使用上面线程中发布的代码合并了这两个excel文件 .
问题在于样式(我创建的样式如下):
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
newCellStyle.cloneStyleFrom(oldCellStyle);
styleMap.put(stHashCode, newCellStyle);
这导致了样式问题“ Repaired Records: Format from /xl/styles.xml part (Styles) ”
经过大量的研究,我学到的是边界和填充是导致问题的原因 . 取消设置这些参数已解决了这个问题 . 但由于它表示边界和填充失踪 .
有人可以围绕如何从单元格获取边框和填充样式并应用于新单元格吗?
3 回答
这似乎是bug in Apache POI, #55800 . 不会复制"CoreXf"对象中使用的边框ID和填充ID,从而导致出现问题 .
根据Comment 5 on that bug,可以通过自己手动复制填充和边框属性来解决它 .
for(String str:numberFormats.values())
stylesTable.putNumberFormat(STR);
for(XSSFFont font:fonts){
XSSFFont fontNew = new XSSFFont(font.getCTFont());
fontNew.registerTo(stylesTable);
}
for(XSSFCellFill fill:fills){
XSSFCellFill fillNew = new XSSFCellFill(fill.getCTFill());
stylesTable.putFill(fillNew);
}
for(XSSFCellBorder border:borders){
XSSFCellBorder borderNew = new XSSFCellBorder(border.getCTBorder());
stylesTable.putBorder(borderNew);
}
for(CTXf ctxf:styleXfs){
CTXf ctxfNew =(CTXf)ctxf.copy();
stylesTable.putCellStyleXf(ctxfNew);
}
for(CTXf ctxf:xfs){
CTXf ctxfNew =(CTXf)ctxf.copy();
stylesTable.putCellXf(ctxfNew);
}
for(CTDxf dxf:dxfs){
CTDxf dxfNew =(CTDxf)dxf.copy();
stylesTable.putDxf(dxfNew);
}
}
发表于https://issues.apache.org/bugzilla/show_bug.cgi?id=55800的帖子
因为我们遇到边框和填充问题
添加下面的代码像Charm一样工作
您可以使用以下代码 . 我用.xlsx进行了验证,我相信它也适用于.xls .