Problem while upgrading the Obsolete method Worksheet.SheetToImage() method


While upgrading from Aspose.Cells 4.8 version to upgrade to 5.2 version, I got several obsolete method warnings.

So the code which I want to want to upgrade is:

Workbook.Worksheets[dataSheetIdx].SheetToImage("ImageName.emf", System.Drawing.Imaging.ImageFormat.Emf);

and I replaced the above code with the code written below in the latest (5.2) version:

ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.ImageFormat = ImageFormat.Emf;
SheetRender render = new SheetRender(Workbook.Worksheets[dataSheetIdx], imageOrPrintOptions);
render.ToImage(0, "ImageName.emf");

First of all, Just wanted to confirm that the code changes are correct?
Secondly, Can I get single image for all the page in Worksheet.

Ankush Chauhan


Yes, the updated code is fine.

See the documents for your complete reference about Sheet to Image feature.

To get a single page for a worksheet, you may add:

//Only one page for the whole sheet would be rendered

imageOrPrintOptions.OnePagePerSheet = true;