Skip to content

WrapExcel is a wrapper library that specializes in the operation of Excel win32ole.

License

Notifications You must be signed in to change notification settings

Thomas008/wrap_excel

 
 

Repository files navigation

WrapExcel

This is a simple fork from tomiacannondale’s wrap_excel adapted to Ruby 1.8.6.

RobustExcelOle is another project that has started with WrapExcel. It robustly wraps the win32ole library and allows to perform various operations in Excel with ruby.

See github.com/Thomas008/robust_excel_ole

Description

WrapExcel is a to wrap the win32ole, and easy to use Excel operations with ruby.

Requirements

  • Ruby 1.9.2 or higher (platform is windows)

  • also works with Ruby 1.8.6

Install

gem install wrap_excel

Usage

access book

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)

access sheet

Sheet object can access with Book#[] method.

sheet = book[0]

Access with sheet name.

book['Sheet1']

access row or column

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

access cell

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

write excel

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.

Want to do more things

All WrapExcel object include win32ole instance. If you want to do something that not provide a function, you can use win32ole methods.

Support

Report issues and feature requests to github Issues. github.com/tomiacannondale/wrap_excel/issues

Collaborate

Please pull request on github.

Author

tomi [email protected]

License

MIT License. For more imformation, please see LICENSE.

About

WrapExcel is a wrapper library that specializes in the operation of Excel win32ole.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 88.5%
  • CSS 11.5%