Free Support Forum -

Size of rendered file - huge

Good day.

I have been rendering excel worksheets to image for some time now. Usually it causes no problem.
But using the attached .xls file, it renders an image that is much larger than the document.

I am using the following code (ColdFusion):

<cfset wb = createObject(“java”,“com.aspose.cells.Workbook”).init(filexls)>

<cfset ws=wsc.get(javacast(“int”,0))>

<cfset ws=wsc.get(javacast(“int”,0))>

<cfset pageSetup.setBottomMargin(javacast(“int”,0))>
<cfset pageSetup.setTopMargin(javacast(“int”,0))>
<cfset pageSetup.setLeftMargin(javacast(“int”,0))>
<cfset pageSetup.setRightMargin(javacast(“int”,0))>

<cfset ipo=createObject(“java”,“com.aspose.cells.ImageOrPrintOptions”)>
<cfset ipo.setHorizontalResolution(javacast(“int”,200))>
<cfset ipo.setVerticalResolution(javacast(“int”,200))>
<cfset ipo.setOnePagePerSheet(javacast(“boolean”,true))>
<cfset ipo.setImageFitToPage(javacast(“boolean”,true))>
<cfset imageFormat=createObject(“java”,“com.aspose.cells.ImageFormat”).getPng()>
<cfset ipo.setImageFormat(imageFormat)>
<cfset sr=createObject(“java”,“com.aspose.cells.SheetRender”).init(ws,ipo)>
<cfset sr.toImage(0,tempPNGFile)>

When I output the maxDataRow() and maxDataColumn() of cells, it indicates 55 and 5, respectively, which is correct; it is not expanding the image to fit an “outlier” cell.

I would appreciate it if you can tell me if you replicate the same results I am seeing. Thank you.

I think the answer might lie in the fact that the “Print to Fit” rendering is printing all cells that have some sort of formatting “turned on” (in this case, fill color) even though the data itself does not extend that far.

If that is the case, do you have a suggestion on how I can “Print to Fit” only those cells that have data?

Thank you.


If you could open your template file and see its print preview into MS Excel, you will see that there are 40 pages to be rendered. Aspose.Cells follows MS Excel standards by default. I think for your needs, you have to specify your printable area for the sheet’s page setup options. See the following code below, I used simple JAVA code here, you may convert it to ColdFusion accordingly.

The following code generated only four image files as per your requirements based on data pages only, all the blank or other pages are not rendered now.

Sample code:

String path = “f:\files\sizeof\breakme.xls”;
Workbook wb = new Workbook(path);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
WorksheetCollection worksheets = wb.getWorksheets();
for(int idx = 0; idx<worksheets.getCount(); idx ++)


Worksheet sheet = worksheets.get(idx);
int maxdatacol = sheet.getCells().getMaxDataColumn();
int maxdatarow = sheet.getCells().getMaxDataRow();
String cellname = CellsHelper.cellIndexToName(maxdatarow, maxdatacol);
sheet.getPageSetup().setPrintArea(“A1:” + cellname);

SheetRender sr = new SheetRender(sheet, imgOptions);
for(int i = 0;i<sr.getPageCount();i++)
sr.toImage(i, path + “_” + sheet.getIndex() + i +".png");



Let us know if you still have any confusion or issue, we will be happy to assist you here.

Thank you.