我有一个简单的脚本,应该读取 excel 并打印两个单元格:
require 'rubygems'
gem 'ruby-ole','1.2.11.4'
require 'spreadsheet'
class Filter
# Gets zipcode range
def get_zipcode_range
wb = Spreadsheet.open "../data/zipcode_range.xls"
sheet = wb.worksheet 0
[sheet.cell(0, 0), sheet.cell(0, 1)]
end
end
f = Filter.new
puts f.get_zipcode_range
文件结构如下:
FilterExcel
data
zipcode_range.xls
lib
filter.rb
当我打开命令提示符并转到 FilterExcel\lib 并运行时:
ruby filter.rb
它给出了预期的输出:
3911AW
3911ZZ
但是当我从项目根文件夹 FilterExcel 运行脚本时,它会引发错误:
C:\Documents and Settings\Erik\FilterExcel>ruby lib\filter.rb C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet.rb:68:in '初始化':没有这样的文件或目录 - 来自 C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet 的 ../data/zipcode_range.xls (Errno::ENOENT) .rb:68:in 'open' 来自 C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.7.4/lib/spreadsheet.rb:68:in 'open' 来自 lib/filter。 rb:56:in 'get_zipcode_range' 来自 lib/filter.rb:63:in ''
PS如果重要的话,我使用Windows XP。