[英]How to update a XSLFTable (table in .pptx presentation) using Apache POI?
我正在使用Apache POI,並且正在嘗試使用Powerpoint報告自動執行某些任務。 更准確地說,我想通過代碼(包括表格)更新.pptx演示文稿中的數據。
我已經設法獲取XSLFTable對象(感謝此頁面: 如何使用apache-poi 3.9修改pptx文件中表的單元格值? ),但是現在我試圖更新表結構。
不幸的是,我不知道如何在該表中創建或刪除行(或列)。 方法getRows
返回一個列表,但是它似乎不可修改。 有一個addRow
方法,但是我沒有找到任何要刪除/刪除行的方法。
你知道我怎么能做到嗎?
非常感謝,並致以最誠摯的問候!
獲取XSLFTable
XSLFTable t = null;
for (XSLFShape shape : slide) {
if (shape instanceof XSLFTable) {
t = (XSLFTable) shape;
r = t.getRows();
}
}
添加行和單元格
XSLFTableRow titleRow = tbl.addRow();
titleRow.setHeight(50);
XSLFTableCell titleCell1 = titleRow.addCell();
XSLFTextParagraph p1 = titleCell1.addNewTextParagraph();
p1.setTextAlign(TextAlign.CENTER);
XSLFTextRun r1 = p1.addNewTextRun();
r1.setText("Column title");
r1.setBold(true);
r1.setFontColor(new Color(0, 104, 145));
titleCell1.setFillColor(new Color(190, 230, 245));
r1.setFontSize(25.0);
titleCell1.setVerticalAlignment(VerticalAlignment.MIDDLE);
刪除行
t.getCTTable().getTrList().remove(t.getNumberOfRows()-1); //Remove the last row from table.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.