How to modify the cell value of a table in an pptx file with apache-poi 3.9?

久未见 提交于 2019-12-08 06:58:31

问题


I'm trying to modifify 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? Thanks in advanced, Meg


回答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.



来源:https://stackoverflow.com/questions/19975379/how-to-modify-the-cell-value-of-a-table-in-an-pptx-file-with-apache-poi-3-9

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!