'How to modify the cell value of a table in an pptx file with apache-poi 3.9?
I'm trying to modify the cell value of a table within a pptx file. 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".
Could someone help me?
Solution 1:[1]
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).
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
