0

我正在尝试使用电子表格gem 简单地向现有的 excel 文件添加一行。

test_url = "#{Rails.root}/data/Skipped_Records.xls"

if File.exists?(test_url)
    book = Spreadsheet.open(test_url)
else 
    book = Spreadsheet::Workbook.new
    book.create_worksheet
end

sheet = book.worksheet(0)
last_index = sheet.row(-1).idx
sheet.row(last_index + 1).concat [index, error] 
book.write "#{Rails.root}/data/Skipped_Records.xls"

在第一次运行中,文件创建得很好。但在第二次运行后,打开文件 LibreOffice 说

Unknown or unsupported excel file format.

我正在尝试使用 rake 任务将 excel 数据迁移到 rails 应用程序。在执行此操作时,由于某些错误而跳过了几行。我正在尝试记录这些跳过的记录。

请帮忙。

4

0 回答 0