Reputation: 2771
Even if I Just load and save an existing Excel (.xlsx) file, its format is corrupted. Here is what I am doing:
ExcelPackage pck = new ExcelPackage(fileInfo);
pck.SaveAs(newFile);
Any idea of how can I retain original formating settings of Excel file editted through EPPlus?
UPDATE
This is the message I see when opening the saved file:
Thanks in Advance
Upvotes: 4
Views: 1340
Reputation: 3059
You need to add at least one sheet.
Later versions will throw an error on Save() with a descriptive error message.
Upvotes: 0
Reputation: 2458
Now that I saw the error message I understand.
EPPlus works only with new Excel format (xlsx). It seems that you specify the .xls
extension in SaveAs
operation. So the resulting file is an Excel 2007 or newer but it's extension says it's an Excel 2003 file and this confuses Office Excel.
Try with .xlsx
extension:
FileInfo fileInfo = new FileInfo("jjjjjjj.xlsx");
Upvotes: 0
Reputation:
To save files to a storage location, specify the file name (complete with storage path) and desired file format (from the SaveFormat enumeration).
Upvotes: 1
Reputation: 9700
What do you mean exactly by "format is corrupted" ?
Your file is probably using some specific features, which are not fully supported by ExcelPackage. Especially if they come from most recent releases of Excel. Did you look at the project page for them and in the issue list ?
If I'm not wrong, ExcelPackage isn't maintained anymore but "EPPlus" is a fork which deserves to be tried. Could you upgrade to it ? edit : sorry I've just seen you're already using EPPlus, i was misleaded by the code sample. The other advices remains probably useful though.
Upvotes: 1