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

broken xlsx using conditional formatting... #402

Closed FlauzerOriginal closed 3 years ago

FlauzerOriginal commented 4 years ago

HI,

i am using version 2.5.1. With NPOI, i obtain a corrupted or broken xlsx.

This test file was reduced as it had more than one sheet in production..., but even with only one sheet, it doesn't work. It uses the "conditional formatting".

You can try by simply opening and saving the file ERRORE.xlsx

  1. Open file in attach....

XSSFWorkbook workbook = new XSSFWorkbook(FileStream); _sheet = workbook.GetSheetAt(0)

and simply save this

_sheet.Workbook.Write(FileStream);

Any hints ?

Thanks in advance.

ps. the same with v2.4.1

RomeoDev777 commented 4 years ago

I can confirm that it does happen with 2.5.1 version. If I open an Excel file, created by NPOI, in Excel and simply adjust the row width in the file, save changes and close the file, then open the same file with NPOI and write some data to a new sheet, save it and close it, the file will be corrupted.

nitz commented 3 years ago

I'm using 2.5.2 and also experiencing this issue. I've even tried only having NPOI touch a plain, data only sheet, but it seems the corruption occurs even the sheet elsewhere uses conditional formatting. Unfortunate that this is a blocking issue for us.

tonyqus commented 3 years ago

@RomeoDev777 @nitz Please provide your original Excel files. Although you are all complaining the conditional formatting, the issue you encountered may be different. I can only figure this out by the Excel file.

nitz commented 3 years ago

Good point! I've attached files here to demonstrate the issue.

cf-test.xlsx - The file after having being modified by this code. Will fail to load in Excel 365. cf-test-unmodified.xlsx - The file contents before unmodified. Was based on one of our workbooks, cut down to an extremely small subset that still produced the issue.

The code that modifies the file for this test was run from LINQPad 6, using NPOI 2.5.2 from NuGet.

Let me know if any other information would be useful!


Attachments

cf-test.xlsx cf-test-unmodified.xlsx

tonyqus commented 3 years ago

@nitz After some iinvestigation, your issue is caused by fileRecoveryPr appears after ExtLst. This is not allowed.

nitz commented 3 years ago

Awesome, thanks so much for looking into this! Hope you're well.

FlauzerOriginal commented 3 years ago

@tonyqus Hi, the issue is Closed, ... but,sorry i don't understand: what is "not allowed"? what corrupts the file if the only two code instructions are load (XSSFWorkbook) and save (write) ? Is there someone who can help me?

Thanks in advance.

tonyqus commented 3 years ago

Sorry, the issues from you and @nitz are mixed in this issue. I'm reopening the issue

tonyqus commented 3 years ago

@FlauzerOriginal I had a quick test based on NPOI 2.5.3. The file is fine (not broken). I don't see any conditional formatting lost. Can you test on your side again? If you see some error, please let me know your CultureInfo. It may be caused by different culture formatting.

FlauzerOriginal commented 3 years ago

@tonyqus Awesome, that's great news. I try to test (within a few days) and let you know about it, thanks so much.

FlauzerOriginal commented 3 years ago

@tonyqus

The original file loses the cells color formatting, but after saving, it's "readable" again and is no longer corrupted

Great job @Tony, thanks,