nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.72k stars 1.43k forks source link

Excel file is always modified even if only opened for reading #1318

Closed rh101 closed 6 months ago

rh101 commented 6 months ago

NPOI Version

2.7.0

File Type

Upload the Excel File

Original file: Test_original.xlsx

Resulting file after calling new XSSFWorkbook("Test_original.xlsx") and then closing the file: Test_modified.xlsx

Reproduce Steps

using var workbook = new XSSFWorkbook("Test_original.xlsx");
// Close and dispose workbook
// Input file is modified when it should not be

Issue Description

Opening a file, reading information from it, then closing it, should not be modifying the original input file. At no point was the Excel file modified in code. It can be reproduced by opening the file then closing it using the above snippet of code.

tonyqus commented 6 months ago

You can try WorkbookFactory.Create(inputstream, readonly) method

https://github.com/nissl-lab/npoi/blob/4eb5d0e443204df0e299a3b0ccb75b576b658873/ooxml/SS/UserModel/WorkbookFactory.cs#L124