Manage Worksheets
Managing worksheets using Aspose.Cells for Python via Java is very easy. In this article, we will demonstrate added, accessing, and removing worksheets using the Aspose.Cells API.
Adding Worksheets to a New Excel File
To create a new Workbook, create an object of the Workbook class. The Workbook class represents an Excel file. Then by using the add method of the WorksheetCollection, new worksheets are added to the Excel file. Finally, to save the newly created Excel file, call the save method of the Workbook class.
The following code snippet demonstrates creating a new Excel file and adding a worksheet to it.
Adding Worksheets to a Designer Spreadsheet
Adding worksheets to a designer spreadsheet is exactly the same as adding the worksheet to a new Excel file. The only difference is that instead of creating a new Excel file, we open an existing file by the Workbook class.
The following code snippet demonstrates adding a worksheet to a designer spreadsheet.
Accessing Worksheets using Sheet Name
After loading a workbook, developers can access any worksheet by using its index or name. The following code snippet demonstrates accessing a worksheet by using its name.
Removing Worksheets
There may be times when some sheets meet to be removed from the workbook. For this, the API provides the WorksheetCollection.removeAt method. You can pass it sheet index or sheet name of the sheet to be removed. The following examples demonstrate removing worksheets by using the sheet index and sheet name.