Load Workbook with specified Printer Paper Size
The following sample code illustrates the usage of LoadOptions.set_paper_size() method. It first creates a workbook, then saves it in memory stream in XLSX format. Then it loads it with A5 paper size and saves it in PDF format. Then it loads it again with A3 paper size and saves it again in PDF format. If you open the output PDFs and check their paper size, you will see they are different. One is A5 and the other is A3. Please download the A5 output PDF and A3 output PDF generated by the code for your reference.
from aspose.cells import LoadFormat, LoadOptions, PaperSizeType, SaveFormat, Workbook | |
from io import BytesIO | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create a sample workbook and add some data inside the first worksheet | |
workbook = Workbook() | |
worksheet = workbook.worksheets[0] | |
worksheet.cells.get("P30").put_value("This is sample data.") | |
# Save the workbook in memory stream | |
ms = BytesIO() | |
workbook.save(ms, SaveFormat.XLSX) | |
ms.tell() = 0 | |
# Now load the workbook from memory stream with A5 paper size | |
opts = LoadOptions(LoadFormat.XLSX) | |
opts.set_paper_size(PaperSizeType.PAPER_A5) | |
workbook = Workbook(ms, opts) | |
# Save the workbook in pdf format | |
workbook.save(dataDir + "LoadWorkbookWithPrinterSize-a5_out.pdf") | |
# Now load the workbook again from memory stream with A3 paper size | |
ms.tell() = 0 | |
opts = LoadOptions(LoadFormat.XLSX) | |
opts.set_paper_size(PaperSizeType.PAPER_A3) | |
workbook = Workbook(ms, opts) | |
# Save the workbook in pdf format | |
workbook.save(dataDir + "LoadWorkbookWithPrinterSize-a3_out.pdf") |