2014-01-24 125 views
1

我需要操纵从电子邮件附件中读取的xls文件。由于性能原因,我需要使用Roo宝石。这里的问题是将附件传递给Roo。电子表格宝石可以直接读取StringIO,但Roo似乎没有这种功能。 (Is there any way to get Roo to accept StringIO objects in place of files?用roo打开电子邮件附件

我发现这个解决方案

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) 

但它需要编写一个临时文件,我想摆脱的文件系统。

有没有办法创建一个虚拟文件?

回答

1

没有更好的方法来打开从Roo电子邮件附件的Excel。