I am using Aspose Cells 8.1.0 to create image of the sheet.
I want the image of the sheet to only include the cells that have data with the option of OnePagePerSheet turned on.
However, the image rendered contains lot of white space when I set OnePagePerSheet as true. Image is rendered properly (means without any white space) when I set OnePagePerSheet to false. But I cannot set this to false as there are other cases where data does not fit to one page and I want all the data of the sheet to fit in the single page.
I tried following to achieve this:
- Setting the print area of the populated cells
- Setting ImageFitToPage in ImageOrPrintOptions to true
However no success with both of these.
Is there any option to achieve the desired usecase?
For your reference, I have attached the source excel file and both outputs with OnePagePerSheet as true and false. To analyze the difference between the two images, you may need to open images in MS Paint.
Following is the code snippet being used:
Workbook workbook = new Workbook(“C:/temp/source.xlsx”);
com.aspose.cells.Worksheet sheet = workbook.getWorksheets().get(0);
sheet.getPageSetup().setPrintArea(“A1:D3”);
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.setImageFormat(ImageFormat.getPng());
imageOrPrintOptions.setHorizontalResolution(300);
imageOrPrintOptions.setVerticalResolution(300);
imageOrPrintOptions.setOnePagePerSheet(false);
imageOrPrintOptions.setOnlyArea(true);
SheetRender sr = new SheetRender(sheet, imageOrPrintOptions);
sr.toImage(0, “c:/temp/out2.png”);