excelapache-poilibreoffice

XSSFWorkbook.lockStructure() not working when opening generated XLSX file with LibreOffice


I'm creating a protected XLSX file like this:

XSSFWorkbook wb = new XSSFWorkbook();
wb.lockStructure();
wb.setWorkbookPassword(PASSWORD, null);

When I open the file generated by Excel, I check that it is correctly protected. However, when opening it in LibreOffice, the file is not protected, allowing editing of the structure.

How can I protect it for LibreOffice too? Is it a bug in POI or in LibreOffice?


Solution

  • It is not a bug but a disadvantage while using the Office Open XML *.xlsx file format using OpenOffice or LibreOffice Calc.

    The native file format of OpenOffice or LibreOffice Calc is Open Document Format for spreadsheets *.ods. This format stores Protect Spreadsheet Structure different than Office Open XML *.xlsx stores Protect the workbook structure. Therefore OpenOffice or LibreOffice Calc will and cannot read the setting of Protect the workbook structure while opening a *.xlsx file.

    One might think: What about set Protect Spreadsheet Structure using OpenOffice or LibreOffice Calc and then save that file as *.xlsx? But that will omit the Protect Spreadsheet Structure since Office Open XML *.xlsx is not able to store that. You see that if you close the file after saving as *.xlsx and then reopen it in Calc. The Protect Spreadsheet Structure is gone.

    OpenOffice and LibreOffice warns about these disadvantages while saving a file in Office Open XML file format and suggests using Open Document Format instead.


    On the other hand, this nevertheless seems to be a kind of bug in LibreOffice. At least a regression in development because it seems to have worked before.

    In lock rename of sheet name POI java I provided code to set LockStructure for old binary OLE *.xls files as well as for current Office Open XML *.xlsx files. And LibreQffice is able to read and respect the locked structure of the CreateExcelLockStructure.xls generated but not the locked structure of the CreateExcelLockStructure.xlsx generated. That means LibreOffice is able to read and respect the lock structure of old binary OLE *.xls files but not of Office Open XML *.xlsx files. That sounds not as if it should be so.

    Not really my problem. However, you could ask the LibreOffice developers if anyone is aware of this setback in development.