Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Fri Jul 01, 2022 4:00 pm

I'm using Spire.XLS to generate the preview of XLS files. Some files are complex, and Spire can't generate the PNG (that's ok, some files are really complex, I don't expect Spire to cover all Excel)

The problem is that I can't catch the error and offer the user other option, because the library stalls the entire request (I get ERR_CONNECTION_REFUSED from Chrome)

Code: Select all
       
        public string ExcelAsPNGUrl() {
            try {
                var TempFolder = @"/Content/Temp/";
                var UniquePreviewFileName = ArchivoURL.Replace("/", "_") + ".png";
                if (!System.IO.File.Exists( HttpContext.Current.Server.MapPath(TempFolder + UniquePreviewFileName))) {
                    var workbook = new Spire.Xls.Workbook();
                    workbook.LoadFromFile(HttpContext.Current.Server.MapPath(ArchivoURL));
                    var sheet = workbook.Worksheets[0];
                    sheet.SaveToImage(HttpContext.Current.Server.MapPath(TempFolder + UniquePreviewFileName)); // Here I get a StackOverflow exception
                }
                return @"/Content/Temp/" + UniquePreviewFileName;
            }
            catch (Exception) {
                // *************************************
                // the code never reaches HERE
                return "";
            }
        }





I'm using the latest version 12.2
Attachments
2022-07-01_13-03.png
The exception I get
2022-07-01_13-03.png (39.68 KiB) Viewed 491 times

EduardoMolteni
 
Posts: 6
Joined: Mon Jul 07, 2014 4:35 am

Mon Jul 04, 2022 6:46 am

Hello,

Thanks for your inquiry.

For more complex files, the conversion process requires a lot of system resources, resulting in stackoverflowException. But as far as I know, since .NET 2.0, stackoverflowException cannot be caught by try/catch like normal exception(see this link). So we cannot to catch this exception too.

Also, 12.2 should be the latest version of Free Spire.Xls. So you can also try to update to the latest version 12.6.1 of Spire.Xls first to verify if the problem is resolved.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Jul 04, 2022 1:31 pm

Thanks, I didn't know that, but makes sense. I will try to make the converstion in other request to be sure.

EduardoMolteni
 
Posts: 6
Joined: Mon Jul 07, 2014 4:35 am

Tue Jul 05, 2022 8:18 am

Thanks for your understanding and hope you are doing well!
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.XLS