gpt4 book ai didi

ruby - 无法使用 Roo 将 .xls 转换为 .csv

转载 作者:数据小太阳 更新时间:2023-10-29 08:38:59 25 4
gpt4 key购买 nike

我的代码的目标是处理目录中的所有 .xls 文件并将它们全部转换为 .csv。这在过去有效,但在更新 Ruby 和 Roo 后,它显示以下错误。我正在使用 Ruby 1.9.3-p362 和 Roo 1.11.2。

require 'rubygems'
require 'csv'
require 'iconv'
require 'mysql2'
require 'mysql'
require 'roo'

begin
Dir["#{@work_path}/*.xls"].each do |file|
begin
file_path = "#{file}"
file_basename = File.basename(file, ".xls")
xls = Excel.new(file_path)
xls.to_csv("#{@kenshoo_work_path}#{file_basename}.csv")
@log.info("Converted file #{file}")
FileUtils.remove(file)
@log.info("Deleted file #{file}")
rescue Exception => e
@log.warn("Unable to convert file: #{file_basename} into csv because #{e.message}")
end
end
end

对于每个文件,我都会收到以下错误消息:

Unable to convert file: #{file} into csv because uninitialized constant Excel

感谢任何帮助。谢谢。

最佳答案

rooRoo:: 命名空间中有 Excel 类。您需要将 Excel 的所有实例替换为 Roo::Excel

older versions Roo:: 下没有命名空间类,因此这可以解释为什么您的代码在更新后损坏。

新的存储库在这里:https://github.com/Empact/roo

关于ruby - 无法使用 Roo 将 .xls 转换为 .csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16344069/

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