简体   繁体   中英

Opening email attachment with roo

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?

没有更好的方法可以通过Roo从电子邮件附件中打开Excel。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM