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.PageScale property. This property returns a double value which can be converted to percentage value. For example, if it returns 0.5 then it means scaling factor is 50%.
The following sample code illustrates how to calculate page setup scaling factor using SheetRender.PageScale 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-.NET | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Put some data in these cells | |
worksheet.Cells["A4"].PutValue("Test"); | |
worksheet.Cells["S4"].PutValue("Test"); | |
// Set paper size | |
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4; | |
// Set fit to pages wide as 1 | |
worksheet.PageSetup.FitToPagesWide = 1; | |
// Calculate page scale via sheet render | |
SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions()); | |
// Convert page scale double value to percentage | |
string strPageScale = sr.PageScale.ToString("0%"); | |
// Write the page scale value | |
Console.WriteLine(strPageScale); |