[英]How to modify the cell value of a table in an pptx file with apache-poi 3.9?
I'm trying to modifify the cell value of a table within a pptx file. 我正在尝试修改pptx文件中的表格的单元格值。 Saving the file, the modification is not applied.
保存文件,则不应用修改。
Here is the used 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();
The file C:/Report.pptx does not contain the string "20131028152343" but "#ID". 文件C:/Report.pptx不包含字符串“ 20131028152343”,但包含“ #ID”。 Could someone help me?
有人可以帮我吗? Thanks in advanced, Meg
谢谢,梅格
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 3.10的表上遇到了同样的问题:我无法修改它们,有时文件已损坏(我无法使用LibreOffice打开它)。
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. 我刚刚在构建路径中用
ooxml-schemas-1.1.jar
(可以在Maven Central上找到)替换了jar poi-ooxml-schemas-*.jar
(现在可以在Maven Central上找到)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.