简体   繁体   English

如何使用apache-poi 3.9修改pptx文件中表格的单元格值?

[英]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.

相关问题 如何使用 Apache-POI 为幻灯片中的链接视频创建 pptx 文件 - How to create pptx file for Link-Video in Slide using Apache-POI 通过apache-poi在Excel中更改单元格的值 - Changing value of cell in Excel via apache-poi 如何使用合并的单元格值大于单元格宽度的Apache-POI增加excel行的高度? - How to increase the height of the excel row using Apache-POI having merged cell value greater than the cell width? 如何使用apache-poi获取整个文件内容? - how to get a whole content of file using apache-poi? 如何在apache poi 3.9中读取单元格中每个文本的字体颜色 - How to read font color of each text in cell in apache poi 3.9 如何更改特定单元格apache poi的字体颜色3.9 - How to change font color of particular cell apache poi 3.9 如何使用apache-poi在列中显示对象 - How to display an Object in a column with apache-poi 如何使用Apache POI更新XSLFTable(.pptx演示文稿中的表)? - How to update a XSLFTable (table in .pptx presentation) using Apache POI? Apache-POI:创建电子表格时如何设置单元格的背景色? - Apache-POI : How to set background color of a cell when creating spreadsheet? 使用 Apache-POI 库获取单元格内容时,我得到“无法从文本单元格获取数值”和相反的结果。 我如何解决它? - When getting cell content using Apache-POI Library, I get both “Cannot get a numeric value from a text cell” and the reverse of that. How do I fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM