EasyXLS™ library enables you to protect your Excel file from unauthorized access by setting passwords for opening or / and modifying the document. If you set the password for opening the file, the Excel file will be encrypted.
EasyXLS allows you to create password protected Excel files and also to read password protected Excel files.
The library also provides methods for protecting the workbook structure and windows. An optional password can be set for this purpose. If the workbook is protected, the Excel file will be encrypted. The library allows you to create encrypted Excel files and also to read encrypted Excel files.
For Office 97-2003 documents, you may choose between RC4 (default encryption) or XOR (weak encryption). The default encryption for Office 2007-2013 documents is AES (Advanced Encryption Standard).
The below example shows how to create a password protected Excel file. The exported file is encrypted and a password is set for opening the Excel file.
// Create an instance of the class that exports Excel file, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
// Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password");
// Create Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Password protected and encrypted Excel.xlsx");
' Create an instance of the class that exports Excel file, having two sheetsDim workbook As New ExcelDocument(2)
' Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
' Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password")
' Create Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Password protected and encrypted Excel.xlsx")
C++// Create a pointer to the interface that generates Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Create two sheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
// Set the password for protecting the Excel file when the file is open
workbook->easy_getOptions()->setPasswordToOpen("password");
// Create Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Password protected and encrypted Excel.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel file, having two sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Set the sheet names
workbook->easy_getSheetAt(0)->setSheetName("First tab");
workbook->easy_getSheetAt(1)->setSheetName("Second tab");
// Set the password for protecting the Excel file when the file is open
workbook->easy_getOptions()->setPasswordToOpen("password");
// Create Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Password protected and encrypted Excel.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel file, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
// Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password");
// Create Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Password protected and encrypted Excel.xlsx");
.NET:// Create an instance of the class that exports Excel file
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
// Set the password for protecting the Excel file when the file is open
$workbook->easy_getOptions()->setPasswordToOpen("password");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\\Samples\\Password protected and encrypted Excel.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two worksheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
// Set the password for protecting the Excel file when the file is open
$workbook->easy_getOptions()->setPasswordToOpen("password");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Password protected and encrypted Excel.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel fileset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password")
' Create Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Password protected and encrypted Excel.xlsx")
' Create an instance of the class that exports Excel fileSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2 ("First tab")
workbook.easy_addWorksheet_2 ("Second tab")
' Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password")
' Create Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Password protected and encrypted Excel.xlsx")
' Create an instance of the class that exports Excel fileSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password")
' Create Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Password protected and encrypted Excel.xlsx")
<!-- Create an instance of the class that exports Excel file --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create two sheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Set the password for protecting the Excel file when the file is open --><cfset ret=workbook.easy_getOptions().setPasswordToOpen("password")><!-- Create Excel file --><cfset ret = workbook.easy_WriteXLSXFile(
"C:\Samples\Password protected and encrypted Excel.xlsx")>
.NET:# Create an instance of the class that exports Excel files, having two sheets
workbook = ExcelDocument(2)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
# Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Password protected and encrypted Excel.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files, having two sheets
workbook = gateway.jvm.ExcelDocument(2)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
# Set the password for protecting the Excel file when the file is open
workbook.easy_getOptions().setPasswordToOpen("password")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Password protected and encrypted Excel.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of a password protected Excel file and the password window to enter the required password for opening the file.
Create XLSX, XLSB, XLSM and XLS password protected Excel files
This code sample shows how to create a password protected XLSX file. Similarly, you can create password protected XLS files using ExcelDocument.easy_WriteXLSFile method or create password protected XLSB files using ExcelDocument.easy_WriteXLSBFile method.
EasyXLS allows you to set a password for opening the Excel file using ExcelOptions.setPasswordToOpen method. If password set, the Excel file is encrypted.
If a password is set for opening the Excel file or if the workbook is protected the Excel file is encrypted. EasyXLS supports RC4 (default encryption) or XOR (weak encryption) for Excel 97-2003 files and AES (Advanced Encryption Standard) for Excel 2007-2013 files. The encryption algorithm can be set using ExcelOptions.setEncryptionOptions method.
Getting started with EasyXLS Excel library
To download the trial version of EasyXLS Excel Library, press the below button:
If you already own a license key, you may login and download EasyXLS from your account.