2

I'm working with the Podio application, and I made a tiny little script to grab data from my Podio database and put in an xlsx file, and convert it to a csv using roo.

xlsx = Podio::Item.xlsx( <app_number>, options = {} )

fname = "blah.xlsx"

somefile = File.open(fname, "w")
somefile.puts xlsx
somefile.close
xlsx_data = Roo:Spreadsheet.open(fname)
csv = xlsx_data.to_csv
puts csv

So this works, but printing to a file, only to grab the data back again and convert it to a csv seems...sloppy. Is there a way to not print it to a file, put it in a variable, and then convert it to a csv so I'm not printing files?

I tried using StringIO.new to the output from Podio::Item.xlsx, but I got this as a response:

file = StringIO.new(xlsx)

`extname': no implicit conversion of StringIO into String (TypeError)

Didn't see anything about this in the Podio docs: https://developers.podio.com/doc/items/get-items-as-xlsx-63233 It just mentioned how to export an xlsx file, not what to do with it afterwards.

Any thoughts?

user1428649
  • 83
  • 2
  • 7

1 Answers1

3

Roo::Excelx fakes support of streams by creating temporary file. So you won’t gain any profit avoiding it and passing StringIO instance to it.

I was unable to receive the error you received, but stream support in Roo is kinda cumbersome and I failed to load a stream directly, yielding it from:

StreamIO.new(File.read('/tmp/my_xlsx.xlsx'))

In your case I would go with Tempfile instance, just for the sake of code readability.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160