簡體   English   中英

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

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

我正在嘗試修改pptx文件中的表格的單元格值。 保存文件,則不應用修改。

這是使用的代碼:

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”。 有人可以幫我嗎? 謝謝,梅格

我在使用POI 3.10的表上遇到了同樣的問題:我無法修改它們,有時文件已損壞(我無法使用LibreOffice打開它)。

我剛剛在構建路徑中用ooxml-schemas-1.1.jar (可以在Maven Central上找到)替換了jar poi-ooxml-schemas-*.jar (現在可以在Maven Central上找到)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM