Issue retrieving worksheet dimension

Hi


I’m trying to get the dimension of a worksheet. I’m using the method getPageSize() from the SheetRender class - what I get back is a float array, with 2 values. However when I save the same worksheet as a JPEG the dimension is different from the values I got from the getPageSize() method (about 200 pixels larger in both width and height).
Is there another method to get the dimension of a worksheet, or am I maybe using getPageSize() in a wrong way?

SheetRender renderer = new SheetRender(sheet, options);
float[] floatArray = renderer.getPageSize(0);
int width = Math.round(floatArray[0]);
int height = Math.round(floatArray[1]);
return new Dimension(width, height);

Hi Kevin,


Thank you for contacting Aspose support.

We have evaluated your presented scenario while using the latest version of Aspose.Cells for Java 8.3.1.2 and found that the SheetRender.getPageSize does not return the correct size that corresponds to the resultant image dimensions. We have logged the problem in our bug tracking system under the ticket CELLSJAVA-41160 for further investigation. Please spare us little time to properly analyze the case on our end. In the meanwhile, we will keep you posted with updates in this regard.

Hi Kevin,


Thank you for your patience with us.

We have further investigated the problem as discussed in the ticket logged earlier as CELLSJAVA-41160. The behavior of SheetRender.getPageSize(int pageIndex) method is actually correct because the said method returns the width & height values in Points. In order to convert the Point unit to Pixel, you have to use the formula as stated below.

Pixels = Points * (DPI/72)

Java code will look as follow.

Workbook wb = new Workbook(“D:/temp/PivotTest3.xlsx”);
ImageOrPrintOptions opt = new ImageOrPrintOptions();
opt.setImageFormat(ImageFormat.getJpeg());
SheetRender render = new SheetRender(wb.getWorksheets().get(0), opt);
float[] floatArray = render.getPageSize(0);

int width = Math.round(floatArray[0](96f/72f));
int height = Math.round(floatArray[1]
(96f/72f));

System.out.println(“Width:” + width + " Height:" + height);

Thank you for the quick response!


The documentation at http://www.aspose.com/docs/display/cellsjava/SheetRender needs updating, because it says the method returns values in pixels.

Thank you for solving the issue

Hi Kevin,


Thank you for pointing this out. I have corrected the said article in documentation, and I will make sure that these changes are propagated to future releases as well.