5

I am creating about 10,000 rows with about 50 columns of data. My code looks like this:

  Axlsx::Package.new do |spreadsheet|
    fields.keys.each do |question|
      sortedFields = fields[question].keys.sort
      spreadsheet.workbook.add_worksheet(:name => question) do |sheet|
        # Add spreadsheet header
        sheet.add_row(sortedFields)

        data[question].each do |client,results|
          results.each do |result|
            row =  sortedFields.map{|field|
              result[field] || ""
            }
            sheet.add_row(row)
          end
        end
      end
    end

It is really slow and uses a lot of memory. Is there a way to queue up rows and then add them in bulk, or some other strategy that can improve performance?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
Mike McKay
  • 2,388
  • 1
  • 29
  • 32

0 Answers0