Bug 68652 - Add constructor which allows to prevent writing changes to XSSFWorkbook back to the source file upon closing
Summary: Add constructor which allows to prevent writing changes to XSSFWorkbook back ...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 5.2.3-FINAL
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2024-02-21 08:07 UTC by ydrozhdzhal
Modified: 2024-02-25 09:38 UTC (History)
2 users (show)


Note You need to log in before you can comment on or make changes to this bug.
Description ydrozhdzhal 2024-02-21 08:07:44 UTC
I am using XSSFWorkbook for parsing xlsx files (only reading data).

For XSSFWorkbook creation I am using following constructor:

XSSFWorkbook(String path)

After testing my solution I discovered that there is some unexpected non-transparent undesired behavior:

after closing workbook (I am using try with resources construction) source file is rewritten updated by its compressed version; this is unexpected for me since file is opened only for reading data.

Using following workaround changes this behavior:

static Workbook getWorkbook(String fullFileName) throws IOException {
        try {
            return new XSSFWorkbook(OPCPackage.open(fullFileName, PackageAccess.READ));
        } catch (InvalidFormatException e) {
            throw new IOException(e.toString(), e);

Library version used in my solution is 5.2.5 (not present in version dropdown).
Comment 1 PJ Fanning 2024-02-21 13:50:39 UTC
This has long been the behaviour and we can't change pre-existing behaviour.

We could potentially ass a new constructor to XSSFWorkbook -- eg

public XSSFWorkbook(String, PackageAccess)
Comment 2 ydrozhdzhal 2024-02-21 13:52:54 UTC
It would be nice to add new constructor, I agree.