-3

I have around 1,10,000 records in my database which I want to export to excel sheet. I am able to insert 1,000 records without any issue using "spreadsheet" gem. But after 1,000 real deal start. From 1,000 to 2,000 records, it's very slow insertion with 100% CPU utilization. After 2,000 whole system is crashing.

Create excel sheet with 1,000 records in one excel sheet and then merging excel-sheets is not preferred.

    Environment: 
    Linux-Ubuntu 14.04 OS, 
    Ram: 1GB, 
    Ruby Version: ruby 2.3.1p112
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
teamg
  • 1
  • 1

1 Answers1

0

Don’t use any gems, nor export to the excel format. Produce a CSV.

While it’s a plain text format, excel reads it without any glitch.


Also, MySQL has an ability to export to CSV itself.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • How to use mysql mydb -e "select * from mytable" -B | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > mytable.csv in the ruby script ? – teamg Nov 13 '17 at 12:40
  • Why would you want to use shell command from a ruby script? Just run it from shell, or use the approach with CSV from ruby. – Aleksei Matiushkin Nov 13 '17 at 12:42
  • First of all thanks a ton for taking out time and replying back, really appreciate your help. Well, I am working on a ruby-script which fetches data which is huge and that data has to be inserted in excel sheet. So is the reason I am trying to use this command in ruby-script, which I am failing to do. Look for some solution around. – teamg Nov 14 '17 at 02:51