Password Protection
This chapter introduces how to read and write password-protected Excel files.
Overview
Fesod supports Excel's built-in password protection for both reading and writing. Use .password("xxx") on the builder to encrypt/decrypt files. For .xlsx output, Fesod uses Apache POI's encryption (AES-based) which can be memory-intensive for large workbooks. For legacy .xls files, password protection behaves as write-protection rather than full content encryption, so behavior and security guarantees differ from .xlsx.
Writing with Password
Code Example
@Test
public void passwordWrite() {
String fileName = "passwordWrite" + System.currentTimeMillis() + ".xlsx";
FesodSheet.write(fileName)
.password("your_password")
.head(DemoData.class)
.sheet("PasswordSheet")
.doWrite(data());
}
Reading with Password
Code Example
@Test
public void passwordRead() {
String fileName = "path/to/encrypted.xlsx";
FesodSheet.read(fileName, DemoData.class, new DemoDataListener())
.password("your_password")
.sheet()
.doRead();
}
Security Notes
- Excel password protection encrypts the file content, making it unreadable without the password.
- Without the correct password, reading will throw an
EncryptedDocumentException. - In production, avoid hardcoding passwords — use configuration files or secrets management.