Tag: ruby roo

有没有办法让Roo接受StringIO对象来代替文件?

我正在尝试编写一些涉及Roo阅读Excel 2007文件的unit testing。 我将unit testing文件中的Excel文件作为hex字符串,然后将其输入StringIO实例。 我不能简单地将StringIO对象传递给Roo::Spreadsheet.open ,因为该函数实际上检查传递的对象是否是File实例: def open(file, options = {}) file = File === file ? file.path : file # … 如果不是,继续假设它是一个字符串。 手动指定扩展名没有帮助: doc = Roo::Spreadsheet.open(file, extension: :xlsx) 是否有任何聪明的方法让Roo将StringIO实例用作文件?