Encrypt Excel spreadsheet files (.xls / .xlsx) with an open password (Office Open XML encryption). Opening the output in Excel / WPS requires the password.
.xlsx— encrypted directly.xls— converted to.xlsx(cell values / basic multi-sheet), then encrypted
Add to your application's Gemfile:
gem "spreadsheet_encrypt"Or install locally from source:
bundle exec rake installrequire "spreadsheet_encrypt"
# Positional arguments: input path, password, output path
SpreadsheetEncrypt.encrypt(
"/path/to/input.xls",
"secret-password",
"/path/to/output.xlsx"
)
# Keyword arguments
SpreadsheetEncrypt.encrypt(
input: "/path/to/book.xlsx",
password: "secret",
output: "/path/to/book.encrypted.xlsx"
)Returns the actual output path written (String). If the input is .xls and the output path still ends with .xls, the extension is automatically changed to .xlsx.
bundle exec spreadsheet_encrypt input.xlsx -p secret -o out.xlsx
bundle exec spreadsheet_encrypt input.xls -p secret -o out.xlsx- Encryption targets file open password (not sheet/workbook edit protection).
- Compatible with documents encrypted in the Office 2010+ OOXML style (via ooxml_crypt).
.xlsconversion preserves cell values and multiple sheets; macros, charts, and complex formatting are not guaranteed.
bin/setup
bundle exec rspec
bundle exec rubocopMIT. See LICENSE.txt.