gpt4 book ai didi

Ruby 电子表格:错误的文件描述符 - test.xls (Errno::EBADF)

转载 作者:太空宇宙 更新时间:2023-11-03 18:24:24 24 4
gpt4 key购买 nike

我对制作简单的 .xls 文件并将数据写入一个单元格的脚本有疑问。这是简单的代码:

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

但它会引发错误:

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'

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

最佳答案

因为ruby-ole 1.2.11.5不支持windows平台,更多细节:ruby-ole issue

您可以使用 ruby​​-ole 1.2.11.4 来避免这个问题。

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

关于Ruby 电子表格:错误的文件描述符 - test.xls (Errno::EBADF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13296331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com