1
votes

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?

1
Are you sure that your if statement is being triggered? What happens if you print out the value of text as your code runs, do you see the text you expect?Gagravarr
@Gagravarr I am facing the same problem. And yes, the if statement is triggered and calling getText() after setText() returns the right value.Benoît Guédas
If you write the file out, then read it back in again with Apache POI, does POI see the changed text? i.e. is the problem with POI not writing the text to the file, or with POI writing it in a way that PowerPoint doesn't notice?Gagravarr
No, it doesn't, so it looks like it does not write the changes.Benoît Guédas

1 Answers

1
votes

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.