0

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

The Inquisitive Coder
  • 1,085
  • 3
  • 20
  • 43
  • Can you upload that input file somewhere so that I can reproduce your issue and investigate it? Also, what version of GemBox.Spreadsheet are you using? – Mario Z May 17 '22 at 02:58
  • @https://stackoverflow.com/users/2699178/mario-z apologies, I won't be able to upload the file because it contains sensitive data..all I can say is that the issue is not recurring, sometimes, it passes as well which is kind of weird..also, I'm using v47.0.1418 of GemBox.Spreadsheet – The Inquisitive Coder May 17 '22 at 11:06
  • 1
    In that case, you should consider sending a small Visual Studio project that reproduces the issue on [GemBox support](https://support.gemboxsoftware.com/new-ticket). – Mario Z May 17 '22 at 12:42
  • Okay @https://stackoverflow.com/users/2699178/mario-z, I will do so. Meanwhile, I came across a similar issue with with GemBox PDF in the GemBox Support page itself - https://forum.gemboxsoftware.com/t/random-occurrence-of-input-string-was-not-in-a-correct-format-when-loading-a-pdf-document/484 – The Inquisitive Coder May 17 '22 at 12:56
  • 1
    As you may notice, that issue was resolved after the input file was provided. Unfortunately, there is no other way to fix this without investigating the file, the problem is specific to the input file and thus requires it for troubleshooting. – Mario Z May 18 '22 at 02:57

0 Answers0