The project is in a healthy, maintained state
Encrypt existing Excel files with Office Open XML password protection. .xlsx files are encrypted directly; .xls files are converted to .xlsx then encrypted.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0.2
~> 4.0
>= 3.0
~> 2.10
~> 1.2
 Project Readme

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.