简体   繁体   English

Rails导入大型Excel工作表/ Google工作表

[英]Rails importing large excel sheets/google sheets

I am currently working on two projects. 我目前正在研究两个项目。

One has an excel file with size of about 130mb and you can image how much records it would be containing. 一个包含一个大小约为130 mb的excel文件,您可以对其包含的记录进行映像。

Other is using google sheets with records 25k+ and these will increase over times. 其他人正在使用记录超过25k的google工作表,并且这些记录会随着时间的推移而增加。

So for such mega uploads how should I go about in rails. 因此,对于如此庞大的上传,我应该如何处理。 I am not finding a detailed tutorial addressing this issue, if someone has it then please share it with me. 我找不到解决此问题的详细教程,如果有人遇到了,请与我分享。

Kindly advise me a strategy/gems that I should prefer. 请给我一个我应该首选的策略/宝石。

Thanks. 谢谢。

Have you concidered converting to CSV and then importing? 您是否考虑过转换为CSV然后导入? There's a tutorial and Gem for that: RailsCasts 396 这里有一个教程和宝石: RailsCasts 396

First, export to CSV. 首先,导出为CSV。 Then split into smaller files, fow example with 然后分割成较小的文件,例如

split data.csv

(OS X/Linux) (OS X / Linux)

I'd implement the import as a rake task. 我会将导入作为rake任务来实现。 You could also just generate seed.rb with a bit of string manipulation. 您也可以通过一些字符串操作来生成seed.rb。

Rails shouldn't have a problem with a 170MB file, but it's often annoying to wait for long-running tasks to finish, especially if you're still debugging. Rails的170MB文件应该没有问题,但是等待长时间运行的任务完成常常很烦人,尤其是在调试的时候。

Alternatively, you can probably import it much faster if you talk directly to mysql. 另外,如果直接与mysql通讯,则可能可以更快地导入它。 But you'll loose the convenience of rails and should at least do a 但是,您将失去使用Rails的便利,并且至少应该做一个

Data.all.each do |datum|
   datum.touch
   datum.save!
end

to verify. 核实。

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

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