Calculate Page Setup Scaling Factor with C++
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 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.GetPageScale() property.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main() {
Aspose::Cells::Startup();
// Create workbook object
Workbook workbook;
// Access first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Put some data in these cells
worksheet.GetCells().Get(u"A4").PutValue(u"Test");
worksheet.GetCells().Get(u"S4").PutValue(u"Test");
// Set paper size
worksheet.GetPageSetup().SetPaperSize(PaperSizeType::PaperA4);
// Set fit to pages wide as 1
worksheet.GetPageSetup().SetFitToPagesWide(1);
// Calculate page scale via sheet render
ImageOrPrintOptions options;
SheetRender sr(worksheet, options);
// Convert page scale double value to percentage
double pageScale = sr.GetPageScale();
std::wstring strPageScale = std::to_wstring(pageScale * 100) + L"%";
// Write the page scale value
std::wcout << strPageScale << std::endl;
Aspose::Cells::Cleanup();
return 0;
}