简体   繁体   English

Ruby Spreadsheet:错误的文件描述符 - test.xls(Errno :: EBADF)

[英]Ruby Spreadsheet: Bad file descriptor - test.xls (Errno::EBADF)

I have problem with script that makes simple .xls file and writes data to one cell. 我有脚本的问题,生成简单的.xls文件并将数据写入一个单元格。 Here is simple code: 这是简单的代码:

require 'spreadsheet'

class Filter
  def filter
    @excel = Spreadsheet::Workbook.new
    @sheet = @excel.create_worksheet

    @sheet[0, 0] = "test"
        @excel.write 'test.xls'
  end
end

f = Filter.new
f.filter

But it raises error: 但它引发了错误:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.5/lib/ole/storage/base.rb:62:in write_nonblock': Bad file descriptor - test.xls (Errno::EBADF) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.5/lib/ole/storage/base.rb:62:in initialize' C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.5/lib/ole/storage/base.rb:62:in write_nonblock': Bad file descriptor - test.xls (Errno::EBADF) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.5/lib/ole/storage/base.rb:62:in initialize'

  from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.5/lib/ole/storage/base.rb:78:in 

new' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.5/lib/ole/storage/base.rb:78:in open' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/excel/writer/workbook.rb:4 53:in write_from_scratch' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/excel/writer/workbook.rb:6 31:in write_workbook' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/writer.rb:15:in block in write' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/writer.rb:14:in open' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/writer.rb:14:in write' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/workbook.rb:116:in write' new' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.5/lib/ole/storage/base.rb:78:in open'from C:/ Ruby193 / lib /ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/excel/writer/workbook.rb:4 53: write_from_scratch' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/excel/writer/workbook.rb:6 31:in来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4的write_workbook' /lib/spreadsheet/writer.rb:15:in block in write' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/writer.rb:14:in打开'来自C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/writer.rb:14:in write' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/workbook.rb:116:in in write' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet/workbook.rb:116:in write'

  from filter.rb:10:in `filter' from filter.rb:15:in `<main>' 

because ruby-ole 1.2.11.5 doesn't support windows platform, more detail: ruby-ole issue 因为ruby-ole 1.2.11.5不支持windows平台,更多细节: ruby-ole问题

you can use ruby-ole 1.2.11.4 to avoid this problem. 你可以使用ruby-ole 1.2.11.4来避免这个问题。

require 'rubygems'
gem 'ruby-ole','1.2.11.4'
require 'spreadsheet'

I've seen these before. 我以前见过这些。 First verify that you can write to that file's location. 首先验证您是否可以写入该文件的位置。 My guess is either the file is already open in Excel or your antivirus is blocking the 'threat'. 我的猜测是文件已在Excel中打开,或者您的防病毒软件阻止了“威胁”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行“ rails test”会引发错误的文件描述符(Errno :: EBADF)错误 - Running “rails test” is throwing Bad file descriptor (Errno::EBADF) error 使用jruby会导致“ Errno :: EBADF:错误的文件描述符”错误 - use of jruby causes “Errno::EBADF: Bad file descriptor” error Puma Listen循环错误:# <Errno::EBADF: Bad file descriptor> 在puma.rb配置中 - Puma Listen loop error: #<Errno::EBADF: Bad file descriptor> in puma.rb config Heroku应用程序崩溃,错误H10,open.rb中的文件描述符错误(Errno :: EBADF) - Heroku app crashing, error H10, bad file descriptor in open.rb (Errno::EBADF) JRuby-方法“ eval”的第二次调用给出(Errno :: EBADF)错误的文件描述符 - JRuby - second call of method “eval” gives (Errno::EBADF) Bad file descriptor 红宝石文件锁定错误在Solaris中的Errno :: EBADF - ruby file locking error Errno::EBADF in solaris Mongrel挂在100%CPU / EBADF上(错误的文件描述符) - Mongrel hangs with 100% CPU / EBADF (Bad file descriptor) Ruby守护程序中的错误文件描述符 - Bad File Descriptor in Ruby Daemons exec()用ruby 2.1.1抛出Errno :: EBADF - exec() throws Errno::EBADF with ruby 2.1.1 Ruby电子表格:在xls文件中获取列数 - Ruby spreadsheet : getting column count in xls file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM