This project has moved. For the latest updates, please go here.

SaveAs throws "Input string was not in a correct format."

Sep 6, 2011 at 8:51 PM

I am constructing a worksheet from scratch using InsertTable method using a list of objects.

When I call the SaveAs method to save the worksheet to a MemoryStream it throws a System.FormatException  with the message "Input string was not in a correct format."

Stack Trace:

   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
   at System.Double.Parse(String s)
   at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context)
   at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document)
   at ClosedXML.Excel.XLWorkbook.CreatePackage(Stream stream, Boolean newStream)
   at ClosedXML.Excel.XLWorkbook.SaveAs(Stream stream)
   at MediatechBusinessLayer.StewardBLL.GetAllocatedGoals(Int64 steward_ID, String& errString) in ... \StewardBLL.cs:line 579
NOTE that this works with ClosedXML version 56.3 but fails in ClosedXML version 57.3
Is it possible that this was fixed in a more recent version?
Coordinator
Sep 6, 2011 at 9:32 PM

Try with the latest check-in. If it doesn't work then please try to identify what element in your collection is breaking or give me a way to reproduce it.

Sep 7, 2011 at 12:57 AM

It also fails with version 58.0. 

I could go back to version 56.3 but then my other code catches the bug in CellsUsed().Count().

Since the Excel sheet that causes the error is generated within a rather large project, I would have to create a separate project to isolate the error to reproduce it. However I can send you the generated Excel sheet from version 56.3 and maybe it will show the error when you try to open it up and save it back again.

I will start a new issue so I can upload the Excel file for you to look at.

Coordinator
Sep 7, 2011 at 12:59 AM

Okay, let's do that.

Sep 7, 2011 at 1:05 AM

Work item # 7135 was created.

Thank you.

Sep 8, 2011 at 3:08 PM

Thank you. Downloaded version 59.0 and the item is fixed.