我对这个有点发疯了。
我正在尝试导入 CSV 文件:
uploaded_io = File.read("amazon_import.csv")
FasterCSV.parse(uploaded_io, {:headers => true, :quote_char => '"', :col_sep => "\t"}).each do |row_data|
new_record = AmazonSale.new(
'asin' => row[0],
'title' => row[1],
'barcode' => row[2].match(/\d+/),
'price' => row[4],
'discount' => row[5],
'cost' => row[7],
'active' => row[8],
'product_group' => row[9],
'release_date' => row[10],
'customer_ordered_units' => row[11],
'shipped_units' => row[12],
'shipped_date' => Date.today - 1,
'shipped_cogs' => row[14],
'sellable_on_hand_units' => row[15],
'unsellable_on_hand_units' => row[16],
'customer_owned' => row[17],
'total_inventory_units' => row[18],
'vendor_units_received' => row[19],
'open_po_qty' => row[20],
'two_week_forecast' => "",
'four_week_forecast' => "",
'category' => "",
'subcategory' => "",
'author' => row[25],
'binding' => "",
'platform' => "",
'cat_no' => row[28]
)
new_record.save
end
我在我的应用程序的其他地方成功地使用了几乎相同的脚本,但是这个脚本抛出了一个错误,例如:
FasterCSV::MalformedCSVError: Illegal quoting in line 70.
违规行如下所示:
0711297466621,£,5.56,20,£,4.45,Active,Music,06/10/2003,2,5,£,22.25,0,0,4,4,1,27,Alternative & Indie,Unknown,"Bragg, Billy",Audio CD,cd,COOKCD266,,
我可以看到这是“布拉格,比利”造成的,并尝试了各种方法来逃避或删除逗号和引号,但我一直收到同样的错误。
任何人都可以帮忙吗?
我在 Ruby 1.8.7 上。