Hello Aspose,
I would like to create a preview image from an excel file using aspose.cells.Rendering.SheetRender, meaning I would render only a part of the file into the image.
It seems the SheetRrender uses the sheet’s printing page breaks (Workseet.GetPrintingPageBreaks()) to render the images, which, unfortunalty i was unable to modify as desired.
Regards.
C.
Hi,
Hi,
I have tried what you suggested.
I’m attaching my code, the excel file and the image output.
My Code:
Worksheet sheet = document.Worksheets[(page - 1)];
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
// sheet.PageSetup.PrintArea = GetSheetPrintArea(sheet.Cells.MaxColumn, sheet.Cells.MaxRow);
sheet.PageSetup.PrintArea = “A1:U151”;
SheetRender renderer = new SheetRender(sheet, imgOptions);
if (renderer.PageCount != 0)
{
Bitmap outputImage = renderer.ToImage(0);
outputImage.Save(output + “test”);
}
Hi,
Thanks for your posting and using Aspose.Cells.
You are actually taking the image of entire worksheet by setting the print area. You can achieve the same thing by setting the ImageOrPrintOptions.OnePagePerSheet property to true. This way, you will get a single image which will cover entire worksheet.
Please see the following code which is same as yours except it is using ImageOrPrintOptions.OnePagePerSheet property now. Now you don’t need to set print area to get the desired results. I have attached the output image for your reference.
C#
Workbook document = new Workbook(“exceldummy.xlsx”);
Worksheet sheet = document.Worksheets[“Blad4”];
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
imgOptions.OnePagePerSheet = true;
SheetRender renderer = new SheetRender(sheet, imgOptions);
if (renderer.PageCount != 0)
{
Size s = renderer.GetPageSize(0);
renderer.ToImage(0, “test.png”);
}
Hi,
Thanks for both replies.
the OnePagePerSheet solved my issue.
Hi,
Thanks for your feedback and using Aspose.Cells.
It is good to know that your issue is resolved with one page per sheet option. Let us know if you encounter any other issue, we will be glad to look into it and help you further.