In this simple topic, you’ll learn how to Remove Password Protection From Excel File using Java REST API. We will develop an application to decrypt Excel file using Java Cloud API by following the detailed and lucid steps mentioned in the following section. The created application can be used with any application supporting Java in macOS, Linux, or Windows environments and conversion can be done for free.
Prerequisite
- Create an account and get API credentials
- Download Aspose.Cells Cloud SDK for Java to decrypt Excel file using Java Cloud API
- Setup Java project with the above SDK to protect an XLS file
Steps to Reset Excel file Password using Java low code API
- Set the Client ID and Client Secret for the API to decrypt the Workbook with a password using Java REST API
- Create an object of the CellsApi class with client credentials to reset Excel file password using Java low code API
- Add the source XLS file names and load the source XLS using a name and File object in a HashMap
- Create an instance of the DeleteUnProtectWorkbookRequest to add the existing password and other properties
- Call the deleteUnProtectWorkbook request method to decrypt excel file with password using Java REST API
- Save the decrypted Excel file/s on the local disk
The aforementioned steps remove password protection on Excel using Java REST API. We will initiate the process with the setting up the SDK and creating the CellsAPI class instance. We will then load the source XLS file/s using a HashMap and create an instance of the DeleteUnProtectWorkbookRequest class that is further used for resetting the password protection for the Excel files using the deleteUnProtectWorkbook() method.
Code to Decrypt Excel file Password using Java REST API
import com.aspose.cloud.cells.client.*; | |
import com.aspose.cloud.cells.model.*; | |
import com.aspose.cloud.cells.request.*; | |
import org.junit.Test; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.io.File; | |
import java.util.HashMap; | |
public class ExampleDeleteUnProtectWorkbook { | |
public void Run(){ | |
try{ | |
String clientID = "ID"; | |
String clientSecret = "Secret"; | |
String apiBaseUrl = "https://api.aspose.cloud"; | |
String apiVersion = "v3.0"; | |
CellsApi cellsApi = new CellsApi(clientID, clientSecret, apiVersion, apiBaseUrl); | |
String remoteFolder = "TestData/In"; | |
// Source and output file names | |
String localPath = "C:/ExcelFiles/"; | |
String inputFileName = "Source.xls"; | |
String pass = "test"; | |
UploadFileRequest uploadFileRequest = new UploadFileRequest(); | |
uploadFileRequest.setPath( remoteFolder + "/" + remoteName ); | |
uploadFileRequest.setStorageName( ""); | |
HashMap<String,File> files = new HashMap<String,File>(); | |
files.put( localName , new File(localName )); | |
uploadFileRequest.setUploadFiles(files); | |
cellsApi.uploadFile(uploadFileRequest); | |
DeleteUnProtectWorkbookRequest request = new DeleteUnProtectWorkbookRequest(); | |
request.setName(remoteName); | |
request.setPassword(pass); | |
request.setFolder(remoteFolder); | |
request.setStorageName(""); | |
cellsApi.deleteUnProtectWorkbook(request); | |
} catch (ApiException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
This simple example code enables you to clear excel file password using Java low code API. You need to provide the source Excel files and existing password for removing protection along with other optional properties. After formulating the Request Message, deleteUnProtectWorkbook() performs the decryption on the Excel file and returns the password cleared Excel files that can stored on the disk or inside the database.
We have learned to decrypt Workbook with Password using Java REST API in this topic. If you want to set the password for an Excel file, refer to the article on how to Password Protect Excel File with Java REST API.