WrapExcel is a to wrap the win32ole, and easy to use Excel operations with ruby.
-
ruby 1.9.2 or higher (platform is windows)
gem install wrap_excel
Read with block.
WrapExcel::Book.open('./sample.xls') do |book| # do something end
Read without block.
book = WrapExcel::Book.open('./sample.xls') book.close
Options are the following.
- read_only
-
boolean(default true)
- displayalerts
-
boolean(default false)
- visible
-
boolean(default false)
Sheet object can access with Book#[] method.
sheet = book[0]
Access with sheet name.
book['Sheet1']
Sheet object is included enumerable. Use Sheet#each_column or Sheet#each_row or Sheet#each method.
sheet.each do |cell| # do something with cell # read every row every column end sheet.each_row do |row| # do something with row_range end sheet.each_column do |column_range| # do something with column_range end
Read from sheet object.
sheet[0, 0] => first cell.
Read from range object
row_range[0] => first cell in row_range column_range[1] => second cell in column_range
Can save an existing file.
WrapExcel::Book.open('./sample.xls', :read_only => false) do |book| # do something book.save end
or
book = WrapExcel::Book.open('./sample.xls', :read_only => false) book.save book.close
Can save an another file name.
WrapExcel::Book.open('./sample.xls', :read_only => false) do |book| # do something book.save './another_file.xls' end
Save to another_file.xls
Can not save new file.
All WrapExcel object include win32ole instance. If you want to do something that not provide a function, you can use win32ole methods.
Report issues and feature requests to github Issues. github.com/tomiacannondale/wrap_excel/issues
Please pull request on github.
tomi tomiacannondale@gmail.com
MIT License. For more imformation, please see LICENSE.