rspreadsheet
Manipulating spreadsheets with Ruby. Read, modify, write or create new OpenDocument Spreadsheet files from ruby code.
Contibutions, ideas and wishes welcomed
Please submit issues and/or fork the repository if you have more ideas, wishes, etc ... If you find a bug you are welcomed to submit a pull request preferably including the failing test.
Examples of usage
require 'rspreadsheet'
book = Rspreadsheet.open('./icecream_list.ods')
sheet = book.worksheets 'Icecream list'
total = 0
(3..20).each do |row|
puts 'Icecream name: ' + sheet[row,2]
puts 'Icecream ingredients: ' + sheet[row,3]
puts "I ate this " + sheet[row,4] + ' times'
total += sheet[row,4]
end
sheet[21,3] = 'Total:'
sheet[21,4] = total
sheet.rows[21].format.bold = true
book.save
This is the basic functionality. However rspreadsheet should allows lots of alternative syntax, like described in GUIDE.md
Installation
Add this line to your application's Gemfile:
gem 'rspreadsheet'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspreadsheet
gem is hosted on Rubygems - https://rubygems.org/gems/rspreadsheet
Motivation and Ideas
This project arised from the necessity. Alhought it is not true that there are no ruby gems allowing to acess OpenDOcument spreadsheet, I did not find another decent one which would suit my needs. Most of them also look abandoned and inactive. I have investigated these options:
- ruby-ods - this one seems as if it never really started
- rodf- this only server as builder, it can not read existing files
- rods - this is pretty ok, but it has terrible syntax. I first thought of writing wrapper around it, but it turned to be not so easy. Also last commit is 2 years old.
- rubiod - this one is quite ok, the syntax is definitely better that in rods, but it seems also very abandoned. It does not support formats. This is a closest match.
- spreadsheet - this does not work with OpenDocument and even with Excel has issues in modyfying document. However since it is supposedly used, and has quite good syntax it might be inspirative. I also find the way this gem handles lazy writing of new rows to Spreadsheet object flawed, as well as strange accesibility of rows array object, which if assigned breaks consistency of sheet.
One of the main ideas is that the manipulation with OpenDOcument files should be forward compatible and as much current data preserving as possible. The parts of the file which are not needed for the change should not be changed. This is different to some of the mentioned gems, which generate the document from scratch, therefore any advanced features present in the original file which are not directly supported are lost.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
