Calculate Page Setup Scaling Factor
Contents
[
Hide
]
When you set Page Setup Scaling using Fit to n page(s) wide by m tall option, Microsoft Excel calculates the Page Setup Scaling Factor. You can calculate the same thing using SheetRender.getPageScale() property. This property returns a double value which can be converted to a percentage value. For example, if it returns 0.5079621076 then it means the scaling factor is 51%.
Calculate Page Setup Scaling Factor
The following sample code illustrates how to calculate page setup scaling factor using SheetRender.getPageScale() property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CalculatePageSetupScalingFactor.class); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Put some data in these cells | |
worksheet.getCells().get("A4").putValue("Test"); | |
worksheet.getCells().get("S4").putValue("Test"); | |
// Set paper size | |
worksheet.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_4); | |
// Set fit to pages wide as 1 | |
worksheet.getPageSetup().setFitToPagesWide(1); | |
// Calculate page scale via sheet render | |
SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions()); | |
// Write the page scale value | |
System.out.println(sr.getPageScale()); |
Console Output
Here is the console output of the above sample code.
0.5079621076583862