Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broken xlsx using conditional formatting... #402

Closed
FlauzerOriginal opened this issue Aug 18, 2020 · 11 comments
Closed

broken xlsx using conditional formatting... #402

FlauzerOriginal opened this issue Aug 18, 2020 · 11 comments
Labels
bug file_error file format generation/writing issue
Milestone

Comments

@FlauzerOriginal
Copy link

FlauzerOriginal commented Aug 18, 2020

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
Copy link

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
Copy link

nitz commented Feb 11, 2021

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
Copy link
Member

tonyqus commented Feb 22, 2021

@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.

@tonyqus tonyqus added bug file_error file format generation/writing issue labels Feb 22, 2021
@nitz
Copy link

nitz commented Feb 22, 2021

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 tonyqus added this to the NPOI 2.5.5 milestone May 25, 2021
@tonyqus
Copy link
Member

tonyqus commented May 25, 2021

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

@nitz
Copy link

nitz commented May 25, 2021

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

@FlauzerOriginal
Copy link
Author

@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 tonyqus reopened this May 27, 2021
@tonyqus
Copy link
Member

tonyqus commented May 27, 2021

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

@tonyqus
Copy link
Member

tonyqus commented May 27, 2021

@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
Copy link
Author

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

@tonyqus tonyqus closed this as completed May 30, 2021
@FlauzerOriginal
Copy link
Author

@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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug file_error file format generation/writing issue
Projects
None yet
Development

No branches or pull requests

4 participants