I tried to change a value of a xlsx-file which is embedded in a docx-file with apache poi. Sadly, I havent found a proper solution to this problem. After running my programm, the new created docx-file with the embedded xlsx-table hasnt changed. Here is what I have tried so far:
FileInputStream fis = new FileInputStream("old.docx");
XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
System.out.println(xdoc.getAllEmbedds().get(0));
File file2 = new File("new.docx");
for (PackagePart pPart : xdoc.getAllEmbedds()) {
String contentType = pPart.getContentType();
// Excel Workbook - OpenXML file format
if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(pPart.getInputStream());
XSSFSheet sheet = embeddedWorkbook.getSheetAt(0);
sheet.getRow(1).getCell(1).setCellValue("someValue"); //change value here
embeddedWorkbook.write(pPart.getOutputStream());
}
}
xdoc.write(new FileOutputStream(file2));
any idea how to fix this problem?