poi修改ppt表格单元格内容不生效
请问各位大神,如题,我在输出文件前,将cell的内容打印出来,结果显示已经修改成功了,但是ppt.write之后,只有文本框内修改成功,表格中未成功。使用XMLSlideShow修改pptx中单元格内容则可成功,这是POI的BUG吗?有解决办法不呢?
关键代码如下:
FileInputStream is = new FileInputStream(inputFilePath);
HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close();
for (HSLFSlide slide : ppt.getSlides()) {
List<List<HSLFTextParagraph>> txts = slide.getTextParagraphs();
Comment[] cos = slide.getComments();
for(Comment co : cos) {
System.out.println(co);
}
for (List<HSLFTextParagraph> txt : txts) {
List<HSLFTextParagraph> paras = txt;
for (HSLFTextParagraph para : paras) {
List<HSLFTextRun> runs = para.getTextRuns();
for (HSLFTextRun run : runs) {
if(run.getRawText() != ""){
String beforeStr = run.getRawText();
String result = beforeStr.replace("1", "*");
run.setText(result);
}
}
}
}
for (HSLFShape sh : slide.getShapes()) {
if(sh instanceof HSLFTable){
HSLFTable table = (HSLFTable)sh;
int columnNum = table.getNumberOfColumns();
int rowNum = table.getNumberOfRows();
for (int i = 0; i < rowNum; i++) {
for (int j = 0; j < columnNum; j++) {
HSLFTableCell cell = table.getCell(i, j);
if (cell != null) { //避免合并单元格造成的空指针异常
String beforeStr = cell.getText();
String result = beforeStr.replace("1", "*");
cell.setText(result).setText(result);
}
}
}
}
}
}
FileOutputStream output=new FileOutputStream(outputFilePath);
ppt.write(output);