简体   繁体   English

NoMemoryError:无法分配内存

[英]NoMemoryError: failed to allocate memory

I have an xlsx file with a lot of data, and I have this script to insert data from the xlsx file into my own database: 我有一个包含大量数据的xlsx文件,并且我有此脚本可以将xlsx文件中的数据插入到我自己的数据库中:

file = 'lib/assets/sicepatfull.xlsx'
xlsx = Roo::Spreadsheet.open(file)
sheet = xlsx.sheet(0)
attrs = sheet.row(1)
data = sheet.parse(header_search: attrs).map do |d|
  d.map {|k, v| [k.parameterize.underscore.to_sym, v] }.to_h.except :id
end
Courier.create!(data)

The command is cancelled after the attrs , and the result is: NoMemoryError: failed to allocate memory . attrs之后取消该命令,结果是: NoMemoryError: failed to allocate memory

How do I fix it? 我如何解决它?

Roo loads the whole file to memory, so if the file is big, it may just be too big for your RAM. Roo将整个文件加载到内存中,因此,如果文件很大,可能对您的RAM来说太大了。

You can use alternative XLSX readers, eg 您可以使用其他XLSX阅读器,例如

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM