0.读取本地文件两个方法:
file = open(path)
lines = file.readlines
lines.each do |line|
p line #" BOOST = self.new(1, '觉醒之书')\n"
end
file = File.open(filePath, "r")
file.each_line do |line|
p line <span style="font-family: Arial, Helvetica, sans-serif;"># BOOST = self.new(1, '觉醒之书')</span>
end
这个方法区别如注释所示,前者会出现双引号和换行符
1.读取excel可以用:roo=>Github官网, roo官网,stackoverflow上的一个提问
值得注意的是如果读取的是xls文件而不是xlsx文件,那么需要gem install roo-xls。open文件时指定类型,如下操作:
require 'roo'
require 'roo-xls'
xlsx = Roo::Spreadsheet.open('/Users/h/Documents/rubyProject/新版本文案.xls',extension: :xls)
puts xlsx.sheet(0).cell('B',2)
2.写excel推荐用 spreadsheet插件
安装方式:gem install spreadsheet
Excel文件生成写入数据实例: