Opening email attachment with roo

386 views Asked by At

I need to manipulate xls files which are read from email attachments. Due to performance reasons I need to use the Roo gem. The problem here is passing the attachment to the Roo. Spreadsheet gem could read StringIO directly but Roo doesn't seem to have such capability. (Is there any way to get Roo to accept StringIO objects in place of files?)

I have found this solution

attachment = mail.attachments.first
file = Tempfile.new(['attachment', '.xls'], :encoding => 'ascii-8bit')
file.write StringIO.new(attachment.body.decoded).read
excel = Roo::Excel.new(file.path)

But it involves writing a temporary file to the file system which I would like to get rid of.

Is there a way to create a virtual file?

1

There are 1 answers

0
Mika On

There is no better way to open an excel from email attachment with Roo.