# Import and Export Encrypted Excel Files

## Content

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>`

## Import Encrypted Excel File

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](/spreadjs/docs/v16/) enumeration, you can specify the error message.
The following code sample shows how to import an encrypted Excel file:

```javascript
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, 
})
```

## Export Encrypted Excel File

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:

```javascript
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,
}
);
```

## Using Designer

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**.

![ImportEncryptedExcel](https://gcdocumentsitekrblob.blob.core.windows.net/document-site-files/images/df1fe1ee-eb3c-4da7-8c20-a0d8d2b7e734/ImportEncryptedExcel.a1105e.gif?width=600)

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**.

![ExportEncryptedExcel](https://gcdocumentsitekrblob.blob.core.windows.net/document-site-files/images/df1fe1ee-eb3c-4da7-8c20-a0d8d2b7e734/ExportEncryptedExcel.70d2de.gif?width=600)