1
votes

I have problem with script that makes simple .xls file and writes data to one cell. 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'

    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:inwrite_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'

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

2 Answers

3
votes

because ruby-ole 1.2.11.5 doesn't support windows platform, more detail: ruby-ole issue

you can use ruby-ole 1.2.11.4 to avoid this problem.

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

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'.