ExcelUtils

Gem Version Build Status Coverage Status Code Climate

Excel utils for easy read and write

Installation

Add this line to your application's Gemfile:

gem 'excel_utils'

And then execute:

$ bundle

Or install it yourself as:

$ gem install excel_utils

Usage

Write

data = {
  'Sheet1' => [
    {column_a: 1.0, column_b: 'some text'},
    {column_a: 2.0, column_b: 1.35},
    {column_a: 3.0, column_b: Date.parse('2019-08-17')},
    {column_a: 4.0, column_b: nil}
  ],
  'Sheet2' => [
    {'Column 1' => 123.0, 'Column 2' => 'Text 1'},
    {'Column 1' => 456.0, 'Column 2' => 'Text 2'}
  ],
  'Sheet3' => []
}

ExcelUtils.write '/path/to/file.xlsx', data

Read

workbook = ExcelUtils.read '/path/to/file.xlsx'
workbook.to_h => # {'Sheet1' => [{'Column A' => 1, ...}, ...], ...}
sheet = workbook['Sheet1']
sheet.name => # 'Sheet1'
sheet.column_names => # ['Column A', ...]
sheet.each # Implements enumerable module (map, to_a, ...)

workbook = ExcelUtils.read '/path/to/file.xlsx', normalize_column_names: true
workbook.to_h => # {'Sheet1' => [{column_a: 1, ...}, ...], ...}
sheet = workbook.sheets.first
sheet.column_names => # [:column_a, ...]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/excel_utils.

License

The gem is available as open source under the terms of the MIT License.