Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import shared Google spreadsheet in Rails

I'm trying to import a shared (to everyone) Google spreadsheet into my database in Rails, using Roo. The following code:

url = 'https://docs.google.com/spreadsheets/d/1-4kCLEXRcIlJB1wK5muZWsIL1nz5NsEWXyLrbe_HJNQ/edit?usp=sharing'
xls = Roo::Spreadsheet.open(url)

gives me

undefined method `spreadsheet_by_key' for nil:NilClass" error message.

Could you suggest what am I doing wrong? What is the easiest way to import a shared Google spreadsheet in Rails?

like image 486
Serge Avatar asked Mar 18 '23 21:03

Serge


1 Answers

Yes, worked like a charm:

url = 'https://docs.google.com/spreadsheets/d/MY_FILE_ID/export?format=xlsx'
xls = Roo::Spreadsheet.open(url, extension: :xlsx)

You were quite right about the "extension" option, it would not work without it.

Thank you a lot!

like image 143
Serge Avatar answered Mar 30 '23 19:03

Serge