SpreadsheetEncrypt

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

Installation

Add to your application's Gemfile:

gem "spreadsheet_encrypt"

Or install locally from source:

bundle exec rake install

Usage

Library

require "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.

CLI

bundle exec spreadsheet_encrypt input.xlsx -p secret -o out.xlsx
bundle exec spreadsheet_encrypt input.xls -p secret -o out.xlsx

Limitations

  • Encryption targets file open password (not sheet/workbook edit protection).
  • Compatible with documents encrypted in the Office 2010+ OOXML style (via ooxml_crypt).
  • .xls conversion preserves cell values and multiple sheets; macros, charts, and complex formatting are not guaranteed.

Development

bin/setup
bundle exec rspec
bundle exec rubocop

License

MIT. See LICENSE.txt.