Spreadsheet: Can not edit XLSX file created with LibreOffice

I have saved an empty XLSX Dokument with
LibreOffice 4.3.6.2
.

I can open the created xlsx file in vaadin spreadsheet and edit. When i save the spreadsheet i get following exception:

Warnung: The part /xl/worksheets/_rels/sheet1.xml.rels does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]

org.apache.poi.openxml4j.exceptions.InvalidFormatException: The part /xl/worksheets/_rels/sheet1.xml.rels does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]

at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:249)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:673)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:253)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:200)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:108)
at com.vaadin.addon.spreadsheet.SpreadsheetFactory.write(SpreadsheetFactory.java:296)
at com.vaadin.addon.spreadsheet.Spreadsheet.write(Spreadsheet.java:2183)

When i try to load the saved file which has been modified by spreadsheet, i get this Exception:

java.io.IOException: Invalid file format.

However, i can still open the saved file in LibreOffice again.

No Problems when editing and saving xlsx files from Microsoft Excel with vaadin spreadsheet.

Tested also with latest apache poi version 3.12-beta1. Still doesnt work with LibreOffice xlsx files.

I hope you noticed
Apache POI bug #54803
, which gives the same error in a bit more special circumstances. If you didn’t do any special modifications to the file before saving, your case sounds like a rather basic use case, so the problem would be nasty. The bug been there for some time, but if it’s a POI issue, then that’s really where it should be fixed.

Its a basic use case indeed. The document created by LibreOffice is empty. Also there is no need to make any modifications in vaadin spreadsheet before saving to reproduce this bug.

I have noticed the reported bug, but its there already for a long time.

i have done more testing without modify the workbook.

private void loadSaveWithPOI() {
    try {
        //filename : libreOffice xlsx document

        FileInputStream fis = new FileInputStream(filename);
        XSSFWorkbook workbook = (XSSFWorkbook) WorkbookFactory.create(fis);
        fis.close();

        //dont make any modification

        FileOutputStream fos = new FileOutputStream(filename);
        workbook.write(fos);
        fos.close();

        //no file format corruption. can be reopened with vaadin spreadsheet

    } catch (Exception e) {
        logger.error(e.fillInStackTrace());
    }
}


private void loadSaveWithVaadinSpreadsheet() {
    try {
        //filename : libreOffice xlsx document

        Spreadsheet sheet = new Spreadsheet(new FileInputStream(new File(filename)));

        //dont make any modification

        sheet.write(filename);

        //file Format gets corrupted after saving. can not be reopened with vaadin spreadsheet

    } catch (Exception e) {
        logger.error(e.fillInStackTrace());
    }
}

As you can see, if only POI library is used to load and save, the file gets not corrupted.

Using vaadin spreadsheet to simply load and save will corrupt the file format of LibreOffice xlsx file.

Ok yeah, I tried your code and the result is indeed a bit different, so the issue occurs in Spreadsheet. It seems that when Spreadsheet reads (probably) or writes the file, it adds a drawing object in the workbook, thereby causing the mentioned Apache POI bug to manifest.

There’s now Vaadin Spreadsheet
ticket #17372
about the issue. We can probably work that out, but the actual POI bug will probably emerge in situations where there’s actual drawings in the document. It may be caused by some missing content type and relationship declarations in the output. You’re welcome to encourage Apache POI developers to fix the issue.

Hi guys,

Just wanted to let you know that this issue has been fixed in version 1.0.4.

Cheers,
/Jonatan

I have used the same code specified in loadSaveWithPOI() method.

But I am getting exception java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.poi.xssf.usermodel.XSSFWorkbook

Please let me know how can I fix this