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;
}
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