GemBox Excel Load Issue - Input string was not in a correct format

259 Views Asked by At

I'm using GemBox to disable the grid lines of a Bulk Excel Export I'm trying to do from my ASP.Net MVC application. Out of many sheets, for a few sheets, however, I'm getting Input string was not in a correct format error. One thing to note is that the issue is not recurring, sometimes it passes as well. Can someone please tell me what am I doing wrong here?

Also, how do I check if the input stream is correct or not before passing it to the Load()? Is there any way?

Below is my code snippet:

private static Stream DisableGridLinesInGemBoxExcel(Stream inputStream) 
    {
            ExcelFile workbookOriginal = ExcelFile.Load(inputStream); // this line throws an error
            var workbookNew = new ExcelFile();

            foreach (var worksheet in workbookOriginal.Worksheets)
            {
                worksheet.ViewOptions.ShowGridLines = false;
                workbookNew.Worksheets.AddCopy(worksheet.Name, worksheet);
            }

            Stream resultStream = new MemoryStream();
            workbookNew.Save(resultStream, GemBox.Spreadsheet.SaveOptions.XlsxDefault);
            return resultStream;
    } 

enter image description here

Additional Note: I came across a similar issue with GemBox PDF in the GemBox support page - Random occurrence of “Input string was not in a correct format.” when loading a PDF document

0

There are 0 best solutions below