[]
SpreadJS supports the import and export of encrypted Excel files. For this, you need to add the following IO reference in your application.
<script src="scripts/gc.spread.sheets.io.0.0.0.min.js"></script>
To import a password-protected Excel file, you need to pass the password
property in the spread's import
method. If the correct password is provided, the file gets imported successfully. However, if an invalid or incorrect password is provided, the errorCallBack
function is triggered, which returns an error. Using the members of the ErrorCode enumeration, you can specify the error message.
The following code sample shows how to import an encrypted Excel file:
const userPassword = 'Asdf0123';
// Import an Excel file with a password.
const errorCallback = (e) => {
if (e.errorCode = GC.Spread.Sheets.IO.errorCode.invalidPassword) {
console.log('Invalid Password!');
} else if (e.errorCode = GC.Spread.Sheets.IO.errorCode.noPassword) {
console.log('Please enter the password!');
}
}
spread.import(file, () => { }, errorCallback, {
fileType: GC.Spread.Sheets.FileType.excel,
password: userPassword,
})
Users can export a password-protected Excel file by specifying the password
property of the spread's export
method. In this case, SpreadJS exports the encrypted Excel file if the password is entered, else it exports the original Excel file without encryption.
The following code sample shows how to export an encrypted Excel file:
const userPassword = 'ABC0123';
const fileName = 'encrypt-export.xlsx';
// Export an Excel file with a password.
spread.export(blob => saveAs(blob, fileName), e => console.log(e),
{fileType: GC.Spread.Sheets.FileType.excel,
password: userPassword,
}
);
You can also provide the password while importing or exporting a protected Excel file in SpreadJS Designer.
To import an encrypted Excel file, click File and then choose Import. On the Import menu page, choose Excel File, specify the settings for importing your file, enter the password in the Password box, and then click Import Excel File.
To export an encrypted Excel file, click File, then choose Export. On the Export menu page, choose Excel File, specify the settings for exporting, enter the password in the Password box, and then click Export Excel File.