Skip to content

Commit d41ab8e

Browse files
authored
Merge pull request #510 from web-ascender/master
Update README.md with more csv examples
2 parents 88afdd7 + 8fa6c30 commit d41ab8e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,18 @@ csv = Roo::CSV.new("mytsv.tsv", csv_options: {col_sep: "\t"})
262262
csv = Roo::CSV.new("mycsv.csv", csv_options: {encoding: Encoding::ISO_8859_1})
263263
```
264264

265+
You can also open csv files through the Roo::Spreadsheet class (useful if you accept both CSV and Excel types from a user file upload, for example).
266+
267+
```ruby
268+
# Load a spreadsheet from a file path
269+
# Roo figures out the right parser based on file extension
270+
spreadsheet = Roo::Spreadsheet.open(csv_or_xlsx_file)
271+
272+
# Load a csv and auto-strip the BOM (byte order mark)
273+
# csv files saved from MS Excel typically have the BOM marker at the beginning of the file
274+
spreadsheet = Roo::Spreadsheet.open("mycsv.csv", { csv_options: { encoding: 'bom|utf-8' } })
275+
```
276+
265277
## Upgrading from Roo 1.13.x
266278
If you use ``.xls`` or Google spreadsheets, you will need to install ``roo-xls`` or ``roo-google`` to continue using that functionality.
267279

0 commit comments

Comments
 (0)