1

This dead-simple code creates a file that Excel won't open.
How could this be failing?

using (SpreadsheetDocument doc = SpreadsheetDocument.Open(@"c:\dir\src.xlsx", true))
{
  doc.SaveAs(@"c:\dir\saved.xlsx");
}

Notes:

  • Excel won't open saved.xlsx
  • src.xlsx is known to exist and be valid (Excel opens it no problem)
  • saved.xlsx is indeed produced, though it's about 500 bytes smaller than src.xlsx
dlchambers
  • 3,511
  • 3
  • 29
  • 34

1 Answers1

1

If you meant this error: Stop debugging before opening the "saved.xlsx" file

I've checked. It works correctly: Output file

  • 1
    The issue was caused by having having src.xlsx open in Excel while accessing it via OpenXml – dlchambers Oct 15 '20 at 11:55
  • Right. The soluation is to stop debugging or close the Excel program during the running. –  Oct 15 '20 at 17:09