上传 excel 文件,然后用 roo 读取文件内容,
报错代码xlsx = Roo::Spreadsheet.open(tmp_file)
报Zip::Error (Zip end of central directory signature not found):
错误
google 有类似,但是解决不了
以下是我的代码
def import
tmp_file = "#{Rails.root}/tmp/import_xls.xlsx"
FileUtils.mv params['import_xls'].tempfile.path, tmp_file
require 'roo'
xlsx = Roo::Spreadsheet.open(tmp_file)
xlsx.each_row_streaming do |row|
begin
order = Order.where(trade_no: "#{row[0]}").first
if not order.blank?
order.update_attributes!(
state: :sent,
express_company: "#{row[7]}",
express_no: "#{row[8]}"
)
end
rescue => exception
Rails.logger.info exception
end
end
render json: { success: 1, msg: "导入成功." }
end