Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Clarify the difference between the usages of Roo::Spreadsheet.open vs Roo::Excelx.new
  • Loading branch information
javierojeda94 authored Sep 30, 2023
1 parent 72dfeef commit 89fb3fd
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,37 @@ gem "roo", "~> 2.10.0"
```
## Usage

Opening a spreadsheet
### Opening a spreadsheet

You can use the `Roo::Spreadsheet` class so `roo` automatically detects which [parser class](https://github.com/roo-rb/roo/blob/master/lib/roo.rb#L17) to use for you.
```ruby
require 'roo'

xlsx = Roo::Spreadsheet.open('./new_prices.xlsx')
xlsx = Roo::Excelx.new("./new_prices.xlsx")
file_name = './new_prices.xlsx'
xlsx = Roo::Spreadsheet.open(file_name)
xlsx.info
# => Returns basic info about the spreadsheet file
```

# Use the extension option if the extension is ambiguous.
xlsx = Roo::Spreadsheet.open('./rails_temp_upload', extension: :xlsx)
``Roo::Spreadsheet.open`` can accept both string paths and ``File`` instances. Also, you can provide the extension of the file as an option:

```ruby
require 'roo'

file_name = './rails_temp_upload'
xlsx = Roo::Spreadsheet.open(file_name, extension: :xlsx)
xlsx.info
# => Returns basic info about the spreadsheet file
```

``Roo::Spreadsheet.open`` can accept both paths and ``File`` instances.
On the other hand, if you know what the file extension is, you can use the specific parser class instead:
```ruby
require 'roo'

xlsx = Roo::Excelx.new("./new_prices.xlsx")
xlsx.info
# => Returns basic info about the spreadsheet file
```

### Working with sheets

Expand Down

0 comments on commit 89fb3fd

Please sign in to comment.