如何修改与Apache-POI 3.9 PPTX文件表格的单元格的值? [英] How to modify the cell value of a table in an pptx file with apache-poi 3.9?
问题描述
我想一个PPTX文件中modifify表格的单元格的值。
保存文件,修改不施加
I'm trying to modifify the cell value of a table within a pptx file. Saving the file, the modification is not applied.
下面是使用code:
FileInputStream is = new FileInputStream("C:/Report_Template.pptx");
XMLSlideShow ppt = new XMLSlideShow(is);
is.close();
ppt.getPageSize();
for(XSLFSlide slide : ppt.getSlides()) {
for(XSLFShape shape : slide){
shape.getAnchor();
if (shape instanceof XSLFTable){
XSLFTable t = (XSLFTable) shape;
List<XSLFTableRow> r = t.getRows();
for (int i = 1; i < r.size(); i++) {
String text = r.get(i).getCells().get(1).getText();
if(text.contains("#ID")) {
r.get(i).getCells().get(1).setText("20131028152343");
}
}
}
}
}
FileOutputStream out = new FileOutputStream("C:/Report.pptx");
ppt.write(out);
out.close();
文件C:/Report.pptx不包含字符串20131028152343,而是#ID。
可能有人帮助我吗?
先谢谢了,
梅格
The file C:/Report.pptx does not contain the string "20131028152343" but "#ID". Could someone help me? Thanks in advanced, Meg
推荐答案
我有表(具有POI 3.10)同一个问题:我无法修改它们,有时,该文件已损坏(我不能打开它LibreOffice的)。
I had the same issue with tables (with POI 3.10): I could not modify them, and sometimes, the file was corrupted (I could not open it with LibreOffice).
我刚刚更换了罐子 POI-OOXML-模式 - *。JAR
与 OOXML-架构 - 1.1.jar
在我的构建路径(你可以找到它的Maven中央),和它的作品了。
I have just replaced the jar poi-ooxml-schemas-*.jar
with ooxml-schemas-1.1.jar
(you can find it on Maven Central) in my build path, and it works now.
这篇关于如何修改与Apache-POI 3.9 PPTX文件表格的单元格的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!