Determine if Paper Size of Worksheet is Automatic with C++

Possible Usage Scenarios

Most of the time, the paper size of the worksheet is automatic. When it is automatic, it is often set as Letter. Sometimes the user sets the paper size of the worksheet according to their requirements. In this case, the paper size is not automatic. You can determine whether the worksheet paper size is automatic by using the PageSetup.IsAutomaticPaperSize property of the Worksheet class.

Determine if Paper Size of Worksheet is Automatic

The sample code given below loads the following two Excel files

and determines whether the paper size of their first worksheet is automatic. In Microsoft Excel, you can check if the paper size is automatic via the Page Setup window as shown in this screenshot.

todo:image_alt_text

Sample Code

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C

    // Source directory path
    U16String sourceDir(u"..\\Data\\01_SourceDirectory\\");

    // Load the first workbook with automatic paper size set to false
    Workbook wb1(sourceDir + u"samplePageSetupIsAutomaticPaperSize-False.xlsx");

    // Load the second workbook with automatic paper size set to true
    Workbook wb2(sourceDir + u"samplePageSetupIsAutomaticPaperSize-True.xlsx");

    // Access the first worksheet of both workbooks
    Worksheet ws11 = wb1.GetWorksheets().Get(0);
    Worksheet ws12 = wb2.GetWorksheets().Get(0);

    // Print the PageSetup.IsAutomaticPaperSize property of both worksheets
    std::wcout << u"First Worksheet of First Workbook - IsAutomaticPaperSize: " << ws11.GetPageSetup().IsAutomaticPaperSize() << std::endl;
    std::wcout << u"First Worksheet of Second Workbook - IsAutomaticPaperSize: " << ws12.GetPageSetup().IsAutomaticPaperSize() << std::endl;

    Aspose::Cells::Cleanup();
}

Console Output

Here is the console output of the above sample code when executed with the given sample Excel files.

First Worksheet of First Workbook - IsAutomaticPaperSize: False

First Worksheet of Second Workbook - IsAutomaticPaperSize: True