如何使用apache-poi 3.9修改pptx文件中表格的单元格值? [英] How to modify the cell value of a table in an pptx file with apache-poi 3.9?

查看:39
本文介绍了如何使用apache-poi 3.9修改pptx文件中表格的单元格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改 pptx 文件中表格的单元格值.保存文件,不应用修改.

I'm trying to modifify the cell value of a table within a pptx file. Saving the file, the modification is not applied.

这是使用的代码:

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();

文件 C:/Report.pptx 不包含字符串20131028152343"而是#ID".有人可以帮助我吗?提前致谢,梅格

The file C:/Report.pptx does not contain the string "20131028152343" but "#ID". Could someone help me? Thanks in advanced, Meg

推荐答案

我在处理表格时遇到了同样的问题(使用 POI 3.10):我无法修改它们,有时文件已损坏(我无法打开它LibreOffice).

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).

我刚刚将 jar poi-ooxml-schemas-*.jar 替换为 ooxml-schemas-1.1.jar(您可以在 Maven Central 中找到它)我的构建路径,现在可以使用了.

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.

这篇关于如何使用apache-poi 3.9修改pptx文件中表格的单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆