EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

Saving XSLM gives currupted error message on opening

Open Guest83 opened this issue 7 years ago • 8 comments

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

MakroTemplate.zip

Guest83 avatar Feb 06 '18 08:02 Guest83

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.

barbedCoil avatar Feb 09 '18 15:02 barbedCoil

This has been fixed, however this need to be reviewed. Here is the pull link

sathishid avatar Feb 10 '18 13:02 sathishid

windows forms application .net 4.5.2

Guest83 avatar Feb 12 '18 06:02 Guest83

Does 4.5.0.3-rc contains the fix? The problem still exist there.

Guest83 avatar Mar 08 '18 11:03 Guest83

The problem still exist in 4.5.1

Guest83 avatar Apr 06 '18 06:04 Guest83

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

MscrmTools avatar Feb 13 '19 15:02 MscrmTools

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 avatar May 27 '19 22:05 Discomnis

@Discomnis nice workaround - thank you

laurence73 avatar Feb 27 '20 15:02 laurence73