This guide explains how to insert a page break in Excel using Python REST API. You will learn to automatically add a horizontal page break in Excel using Python REST API with a Python-based Cloud SDK. It will assist in preparing the horizontal page break request and using it for inserting the page break accordingly.
Prerequisite
- Create an account and get API credentials for inserting a page break
- Download Aspose.Cells Cloud SDK for Python to add a horizontal page break in an Excel file
- Setup a Python project with the above SDK
Steps to Set Page Break in Excel using Python-based API
- Define the clientId, clientSecret, and base API URL to authenticate with Aspose.Cells Cloud
- Instantiate the CellsApi class using your API credentials and base URL to access Excel operations
- Set the file name that will be used for uploading and processing
- Prepare an UploadFileRequest with the file path and stream, and upload it using UploadFile
- Construct a PutHorizontalPageBreakRequest targeting Sheet1 at cell A1, adding a horizontal page break at row 15 and column 1
- Execute the PutHorizontalPageBreak method of the CellsApi to apply the change to the cloud-stored Excel file
- Create a DownloadFileRequest and retrieve the modified workbook containing the page break, and save it
These steps summarize the process of how to insert a page break in Excel using Python REST Interface. This code first connects to Aspose.Cells Cloud using your API credentials, then uploads an Excel file to the cloud. After adding a horizontal page break at a specific spot in the worksheet, it downloads the updated file and saves it to your computer.
Code to Create Page Break in Excel using Python REST Interface
The above code demonstrates how to set page break in Excel using Python REST API. The row property in the PutHorizontalPageBreakRequest defines the page break position. The target sheet is selected by setting the sheetName property.
This article has taught us the process to create a page break. To add a watermark text in an Excel file, refer to the article Add watermark in Excel using Python REST API.