Hi,
How do you render a specific range as an image?
What I want is something that resembles what Excel does.
If you select a range in a sheet in Excel and press copy, you can then paste this range into Paint, Word or whatever other program you want and save it as a picture.
How do you achieve the same thing in Aspose?
I have tried the following but I get white space bottom and right:
var book = new Workbook(“someSource.xlsx”);
Worksheet sheet = book.Worksheets[0];
var range = sheet.Cells.CreateRange(0,0,10,10);
sheet.PageSetup.PrintArea = range.RefersTo;
sheet.PageSetup.LeftMargin = sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;
var options = new ImageOrPrintOptions
{
OnePagePerSheet = true, // setting this to false adds even more whitespace
};
var renderer = new SheetRender(sheet, options);
renderer.ToImage(0, “out.xlsx”);
Best regards,
Hi,
Thanks for your posting and using Aspose.Cells.
Please download and try the latest version: Aspose.Cells
for .NET v8.3.2.5 it should fix your issue.
We have executed your code and it generated the correct image. I have attached the source Excel file used in this code and the output image generated by it for your reference.
C#
var book = new Workbook(“source.xlsx”);
Worksheet sheet = book.Worksheets[0];
var range = sheet.Cells.CreateRange(0, 0, 10, 10);
sheet.PageSetup.PrintArea = range.RefersTo;
sheet.PageSetup.LeftMargin = sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;
var options = new ImageOrPrintOptions
{
OnePagePerSheet = true, // setting this to false adds even more whitespace
};
var renderer = new SheetRender(sheet, options);
renderer.ToImage(0, “out.jpg”);