worksheet.ConvertToImage hangs

Good day people

I'm facing an issue with the XlsIO component where I cannot render an image of an excel file.

The excel file is not that complex, it's 1179 rows and less than 10 columns.

I don't intend to render an image of all that information, that's why I pass the 'lastColumn' and 'lastRow' capped at low values. 

The code is the following, and the bold line never completes:

using (var fs = new FileStream(@"XlsIo.xlsx", FileMode.Open, FileAccess.Read))
{
using (Syncfusion.XlsIO.ExcelEngine engine = new Syncfusion.XlsIO.ExcelEngine())
{
Syncfusion.XlsIO.IApplication app = engine.Excel;
var workbook = app.Workbooks.Open(fs);
var worksheet = workbook.Worksheets[0];
var nrows = worksheet.UsedRange.LastRow;
var ncols = worksheet.UsedRange.LastColumn;
var image = worksheet.ConvertToImage(1, 1, nrows > 40 ? 40 : nrows,
ncols > 7 ? 7 : ncols, Syncfusion.XlsIO.ImageType.Bitmap, null);
MemoryStream ret = new MemoryStream();
image.Save(ret, ImageFormat.Png);
ret.Seek(0, SeekOrigin.Begin);
return ret;
}
}

I've tried with even smaller values at no avail.

I'm sending attached a console app sample project with just one method, which tries to load the xlsx file which is also attached.

I'm using Syncfusion.XlsIO.AspNet.Mvc5 version 19.4.0.48, the project is 32-bit and I cannot change it to 64bit because it's part of another solution already built on 32 bits.

Is this a bug, or known issue?

Thank you for your feedback, regards

Alex




Attachment: SyncfusionXlsIoTest_674111fd.zip

4 Replies

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team February 8, 2022 04:04 PM UTC

Hi Alejandro, 

Greetings from Syncfusion. 
  
The input Excel file contains the hidden images. While trying to convert the worksheet with these images into the image the sample is hanging. To avoid this issue, please remove the images from the worksheet and then convert it. 
  
 
  
Kindly try this suggestion and let us know if the issue is resolved.  
  
Regards, 
Ramya. 
 



AL Alejandro February 8, 2022 09:03 PM UTC

Hello Ramya,

Thank you for your reply.

I deleted the images and the test project worked fine, but the problem is that I cannot modify the excel files since they're uploaded by users, so we are not in control of their creation.

As explained in the original message, I don't need a full/detailed image of the excel worksheet, just something like a preview to show to the users, that's why I capped the lastRow/lastColumn parameters, and the hidden images were far at the end of the file.

Also, the images seem to be small in size, I don't understand why they cause a complete hang of the conversion function. Shouldn't this be considered a bug?

Ramya, do you know a way to just ignore images and other embedded objects in the worksheet when calling ConvertToImage?


Thanks again, regards

Alex






RS Ramya Sivakumar Syncfusion Team February 9, 2022 11:49 AM UTC

Hi Alejandro, 

We have confirmed the issue as Hidden images need to be skipped in the worksheet to image conversion and logged a defect report. We will include the fix for this issue in our upcoming weekly NuGet release scheduled for February 22, 2022.  

You can track the status of defect report through following feedback link. 


We will let you know once the new package version is available on nuget.org. 


As for now please try following code snippet to convert the worksheet to image. 

Code Snippet: 
using (var fs = new FileStream(@"XlsIo-Test.xlsx", FileMode.Open, FileAccess.Read)) 
    using (Syncfusion.XlsIO.ExcelEngine engine = new Syncfusion.XlsIO.ExcelEngine()) 
    { 
         Syncfusion.XlsIO.IApplication app = engine.Excel; 
         var workbook = app.Workbooks.Open(fs); 
         var worksheet = workbook.Worksheets[0]; 
         var nrows = worksheet.UsedRange.LastRow; 
         var ncols = worksheet.UsedRange.LastColumn; 

         workbook.Worksheets.AddCopy(workbook.Worksheets[0], ExcelWorksheetCopyFlags.CopyAll & ~ExcelWorksheetCopyFlags.CopyShapes); 

         var tempSheet = workbook.Worksheets[2]; 

         var image = tempSheet.ConvertToImage(1, 1, nrows > 40 ? 40 : nrows, 
         ncols > 7 ? 7 : ncols, Syncfusion.XlsIO.ImageType.Bitmap, null);        

         MemoryStream ret = new MemoryStream(); 
         image.Save(ret, ImageFormat.Png); 
         ret.Seek(0, SeekOrigin.Begin); 
         return ret; 
    } 


Regards, 
Ramya. 



RS Ramya Sivakumar Syncfusion Team February 23, 2022 08:48 AM UTC

Hi Alejandro, 

We appreciate your patience. 

We have included the fix to resolve the issue Hidden images need to be skipped in the worksheet to image conversion in our weekly NuGet release version 19.4.0.53. Kindly upgrade your Syncfusion packages to this new 19.4.0.53 version and let us know if the issue is resolved. 

Regards, 
Ramya. 


Loader.
Up arrow icon