Implement Custom Paper Size of Worksheet for Rendering with C++
Possible Usage Scenarios
There is no direct option available to create custom paper sizes in MS Excel; however, you can set a custom paper size of your desired worksheets when rendering Excel files to PDF file format. This document explains how to set a custom paper size of a worksheet using Aspose.Cells APIs.
Implement Custom Paper Size of Worksheet for Rendering
Aspose.Cells allows you to implement your desired paper size of the worksheet. You may use the CustomPaperSize method of the PageSetup class to specify a custom page size. The following sample code illustrates how to specify a custom paper size for the first worksheet in the workbook. Please also see the output PDF generated with the following code for reference.
Screenshot
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
// Create workbook object
Workbook wb;
// Access first worksheet
Worksheet ws = wb.GetWorksheets().Get(0);
// Set custom paper size in unit of inches
ws.GetPageSetup().CustomPaperSize(6, 4);
// Access cell B4
Cell b4 = ws.GetCells().Get("B4");
// Add the message in cell B4
b4.PutValue(u"Pdf Page Dimensions: 6.00 x 4.00 in");
// Save the workbook in pdf format
U16String outputDir(u"..\\Data\\02_OutputDirectory\\");
wb.Save(outputDir + u"outputCustomPaperSize.pdf");
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}