This short tutorial guides on how to delete worksheet in Excel using Java REST API. You will learn how to delete an Excel sheet using Java REST Interface through a Java-based Cloud SDK. It shares details to perform this task for multiple Excel files and more than one sheet if required.
Prerequisite
- Create an account and get API credentials for deleting the Worksheet
- Download Aspose.Cells Cloud SDK for Java to remove a sheet
- Setup Java project with the above SDK
Steps to Delete Sheet using Java-based API
- Initialize CellsApi with clientID, clientSecret, and apiBaseUrl for deleting a Worksheet
- Set names for the local disk input file and remote file on the Cloud storage
- Upload local Excel file to Aspose Cloud storage using UploadFileRequest
- Delete worksheet Sheet1 from the uploaded Excel file using the DeleteWorksheetRequest method
- Download the modified file from the cloud using DownloadFileRequest
- Save the downloaded file locally as output.xlsx
- Log success message or catch and print any exceptions
The steps above describe how to delete Excel worksheet using Java Low Code API. The code initializes the Aspose.Cells Cloud API, using provided credentials, uploads a local Excel file to cloud storage and deletes the worksheet named Sheet1 from it. It then downloads the modified file and saves it locally as output.xlsx, displaying a success message upon completion or printing an error if one occurs.
Code to Delete Excel Sheet using Java REST Interface
This sample code demonstrates how to delete Excel page using Java RESTful Service. If the input Excel file has only one sheet, it will be deleted; however, another empty sheet will be added automatically, as zero sheets are not allowed in the Workbook. The UploadFiles() method allows uploading multiple Excel files to the Cloud storage, and DeleteWorksheetRequest can be created and used many times for various uploaded Excel files and desired sheets.
This article has taught us the process of deleting sheets from a Workbook. To remove protection from an Excel file, refer to the article on Remove Password Protection From XLSX File using Java REST API.