We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

[Aspose.Cells] page size in point unit depending on paper type and orientation

Hi,

we’re using Aspose.cells 8.6.3 for providing Excel and Pdf (saveAs) files, based on Excel templates.
I need to compute and set the zoom of a page (page setup of the worksheet) depending on :
- width of the defined print area (sum of columns width of print area … in “point” unit)
- paper type and orientation
- left and right margin

I know how to get all this elements.

But does method exist in Aspose.Cells to get :
- page width in “point” unit depending on paper type and orientation.
or
- page width in “cm” or “inch” unit, the type of the uniy depending on paper type and orientation.
- and, in this case, what is conversion factor from “cm” to “point” or “inch” to "point"

Regards,
Eric Hamel


Hi Eric,


Thank you for contacting Aspose support.

You may consider using the SheetRender.getPageSize method to retrieve the size of a particular page directly in the unit of Points. Please note, the aforementioned method returns an array of type float, where the sequence of values is width & height. Please check the following piece of code for your reference.

Java

Workbook book = new Workbook(sample);
Worksheet sheet = book.getWorksheets().get(0);
ImageOrPrintOptions options = new ImageOrPrintOptions();
SheetRender render = new SheetRender(sheet, options);
float [] size = render.getPageSize(0);
System.out.println("Width: " + size[0] + " Height: " + size[1]);

Hi Babar,

thank you for the answer.
but it doesn’t seem to fit with my needs.

First, what is the unit returned by the method “worksheet.getCells().getColumnWidth(i)” ?
I saw you’ve got same methods to get column width in inches or pixels.

Second point :
I don’t understand why we need to set horizontal and vertical resolution to get the pageSize.
That’s why i think the expression of my needs was wrong.

I need to know the size of the selected paper on the page setup of the sheet.
For example :
A4 -> width 210mm / height 297mm
A3 -> width 297mm / height 420mm
Letter -> width 8,5inch / height 11inch


Then, i can substract right and left margin (pageSetup.getRightMargin() & pageSetup.getLeftMargin()) and i have the size of the possible printing area of my page.
this is "myPageWidth"

If i want to see colums A to Z on a page, i just have to sum columns width from A to Z = "myColumnsWidth"

And then i can set the worksheet.getPageSetup().setZoom(value) with the result of :
myPageWidth / myColumnsWidth * 100

that’s why, I need a way to know the size of the paper and how to convert it in same unit of column width and height.

Regards,
Eric Hamel

Hi Eric,


Thank you for writing back.

Let me explain my previous response so you could have a better insight to achieve you final goal. First of all, you certainly do not require to set the vertical & horizontal resolution to get the printed page size. That was just my test code that I have mistakenly pasted here while posting my previous response, and I removed those statements right away. If you set the resolutions (as mentioned before) the returned values will not correspond to the Paper Type set in the Worksheet’s Page Setup. Regarding the Cells.getColumnWidth(i) method, it returns the value that is the count of word so you should use the Cells.getColumnWidthInch(i) method and multiply it with 72 to get the column width in the unit of points. Moreover, the methods PageSetup.getLeftMargin() & getRightMargin() returns the values in the unit of centimeters (cm) where one cm is equal to 28.346457 points.

Furthermore, if you execute the code from my previous response against any Paper Type set for the Worksheet, you will get the accurate size in the unit of points. For instance, a Worksheet set to print on Letter size paper would return the width & height as 596.44 & 842.68 respectively. Similarly, A2 Paper Type should return Width: 842.68 & Height: 1191.88.

Hi Babar,

thank you for your explanations.
It works fine !!!
For conversions inch <-> point, i use ConvertUtil java class from Aspose.Words.

Wish you an Happy New year.

regards,
Eric Hamel

Hi Eric,


Thank you for your kind response, and it is good to know that you are up & running. Please feel free to contact us back in case you need our further assistance with Aspose APIs.

Happy new year to you as well.