EPPlus
EPPlus copied to clipboard
Saving XSLM gives currupted error message on opening
Opening and saving attached XSLM with following code:
[TestMethod]
public void Test()
{
using (var package = new ExcelPackage(new FileInfo(@"C:\temp\MakroTemplate.xlsm")))
{
package.SaveAs(new FileInfo(@"C:\temp\MakroOut.xlsm"));
}
}
MakroTemplate.xlsm can be opened with Excel. MakroOut.xlsm can not be opened with Excel. Errormsg: "Excel cannot open the file 'MakroOut.xlsm' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file. (OK)"
Tryed with Version 4.1.1 and 4.5.0.2-rc
Do you have any project information, what version of .Net? Project type? Wondering because I have a similar issue in Asp.Net Core 2 with .Net 4.7 Platform running 4.5.0.2rc - my issue is with regular .xlsx file output, same result.
This has been fixed, however this need to be reviewed. Here is the pull link
windows forms application .net 4.5.2
Does 4.5.0.3-rc contains the fix? The problem still exist there.
The problem still exist in 4.5.1
@JanKallman There is a PR for this issue since 10 months now. Can you merge it and push a new release? I would like to avoid forking and maintaining my own repo if possible Thanks!
I have the same issue using the latest EPPLUS and using .net 4.6.2.
The issue is that if your original xlsm does not actually have an existing macro within it, then the serializer used is incorrect.
If you want to work around this without maintaining your own repository I suggest trying to add this:
if (package.Workbook.VbaProject == null)
{
package.Workbook.CreateVBAProject();
}
@Discomnis nice workaround - thank you