EPPlus
EPPlus copied to clipboard
Unable to open workbook after writing with EEPlus
Using version 5.5.2, after writing to an existing workbook we are unable to open it with error message:
"Excel cannot open the file
I debugged a bit and found that:
- This only happens when macros are enabled (*.xlsm file). If I save as *.xlsx the issue does not occur.
- I deleted all Named Ranges from the *.xlsm file and the issue still happens.
- I was able to change the corrupted file to *.zip and extract the contents.
Let me know if there is anything I can do to provide further information. I don't think we would be able to send the file.
Thanks,
Randall
Can you attach the existing xlsm file you are using, so we can reproduce the issue?
I created a brand new macro-enabled Excel file and the issue occurred with that. I zipped up and attached that file. We are simply creating a new ExcelWorksheet in that workbook, and then writing some data to that worksheet.
ExcelWorksheet ws = wb.Worksheets.Add(name); //then write some data to the new worksheet
In case it helps, I also attached the file after the write that has the issue.
This workbook does not have a vbaProject.bin which causes the issue.
If you add this row the issue will go away...
package.Workbook.CreateVBAProject();
If no vbaProject.bin is found EPPlus saves the package as non macro enabled (xlsx), which causes the issue.
I will look into the handling of this, as in this case it gives unexpected results.
Thanks. One question though. If we call
package.Workbook.CreateVBAProject();
Will any VBA macros that existed in the original workbook be lost? If so, I think we would prefer to wait for a fix.
package.Workbook.CreateVBAProject();
will fail if there is a vba project in the file.
You can check that by p.Workbook.VbaProject!=null
Closed due to inactivity.