Free Support Forum - aspose.com

Possible infinite loop in Aspose.Cells.Worksheet.SheetToImage?

Hi,

I’m using Aspose.Cells to generate a thumbnail image for office documents.

Recently, the method Aspose.Cells.Worksheet.SheetToImage hang with high cpu usage for some Excel files.

As a workaround, I’m using a separate thread to call SheetToImage, aborting this thead if it takes too long to complet.

I join two sample excel files if you want to invistigate the problem.

I’m using aspose.cells 4.8.2.0, with a Aspose.Total .NET developper OEM license.

Thanks,

Pascal LE QUANG

Hi,

Please try the attached latest version / fix v4.8.2.5.

I have tested using your template files (I have converted the first sheet in both test1.xls and text2.xls files to images using Worksheet.SheetToImage() method) and it works fine, the conversion speed is fine.

Kindly try it and let us know if you still find any issue.

Thank you.

Unfortunately, it’s still not working for me. Maybe I’m doing something wrong ?

This is the code I’m using to generate the thumbnail :

using (var s = File.OpenRead(path))
{
var workbook = new Workbook();
workbook.LoadData(s);
Image img = workbook.Worksheets[0].SheetToImage();
var outputFile = Path.GetDirectoryName(path) +
Path.DirectorySeparatorChar
+ Path.GetFileNameWithoutExtension(path) + “.jpg”;
img.Save(outputFile, ImageFormat.Jpeg);
}


Hi,

Well, yes, the reason is simple, you are using Workbook.LoadData() method instead of Workbook.Open();

For your information the Workbook.LoadData method would not import drawing objects (including charts) and other settings/attributes from the template file.

Please use Workbook.Open method instead.

using (var s = File.OpenRead(path))
{
var workbook = new Workbook();
workbook.Open(s);
Image img = workbook.Worksheets[0].SheetToImage();
var outputFile = Path.GetDirectoryName(path) +
Path.DirectorySeparatorChar
+ Path.GetFileNameWithoutExtension(path) + “.jpg”;
img.Save(outputFile, ImageFormat.Jpeg);
}


Thank you.