How to refresh embedded content in a pptx using Apache POI?

733 Views Asked by At

Dear all,

I'm working with Apache POI and I'm trying to automate some tasks with Powerpoint reports. More precisely, I would like to update the data inside a .pptx presentation from code, including embedded Excel spreadsheets (displayed as table).

So far, I've managed to update the embedded spreadsheet itself, but the pptx presentation is not "refreshed": when I open the file, the old value is visible, but the new value shows up when I double-click on the grid (entering "edit" mode).

According to Gagravarr's comment this post Unable to see Apache POI updated data value in BarChart in pptx without editing, this behavior is expected: the underlying file is indeed updated, but the pre-rendered version remains.

As a result, I would like to "refresh" the pre-rendered version: do you know how I can do that with Apache POI? (or at least "zap" this pre-rendered version and hope that Powerpoint will re-render it when I open the slideshow).

I'm not familiar with POI users list archives, so I'm sorry if the answer was there somewhere. Thanks a lot, and best regards!

Here is my current code:

// Open SlideShow
FileInputStream fileInputStream = new FileInputStream(sourceFilePath);
XMLSlideShow slideShow = new XMLSlideShow(fileInputStream);
fileInputStream.close();


// Get PackagePart (shortened version)
PackagePart excelEmbedding = slideshow.getAllEmbedds().get(3);


// Update underlying spreadsheet (shortened version)
InputStream is = excelEmbedding.getInputStream();
XSSFWorkbook workbook = new XSSFWorkbook(is);    

XSSFRow row = sheet.getRow(1);
XSSFCell cell = row.getCell(3);
cell.setCellValue("TEST");

OutputStream os = excelEmbedding.getOutputStream();
workbook.write(os);
os.close();
workbook.close();


// Save changes
FileOutputStream fileOutputStream = new FileOutputStream(targetFilePath);
slideShow.write(fileOutputStream);
fileOutputStream.close();
0

There are 0 best solutions below