Q:

How to add column to existing row with axlsx gem?

I am trying to format my xlsx file, but i faced some problems. For example i need to add column to existing row. For example here is my code:
wb.add_worksheet(name: "Sums") do |sheet|
    sheet.add_row ["1.", "Rodiklis"], :style=>[title]
    sheet.add_row ["1.1", "Rekomendacijų vertė"]
    @departaments.each do |departament|
        sheet.add_row ["", departament.name]
    end

    @all_items.each do |summary|
      tyfcb = 0
      rgi = 0
      rgo = 0
      rgirgo = 0
      total = 0
      rgirgo_per_user = 0
      meeting_1_2_1 = 0
      meeting_1_2_1_per_user = 0
      ceu = 0
      ceu_per_user = 0
      v = 0
      v_per_user = 0
      summary.departament.contacts.each do |c|
        items = c.items.where(summary_id: summary)
        tyfcb += c.item_x(items, 'tyfcb')
        rgi += c.item_x(items, 'rgi')
        rgo += c.item_x(items, 'rgo')
        meeting_1_2_1 += c.item_x(items, '1_2_1')
        total += 1
        ceu += c.item_x(items, 'ceu')
        v += c.item_x(items, 'v')
      end
        rgirgo = rgi + rgo
        rgirgo_per_user = rgirgo.to_f / total.to_f
        meeting_1_2_1_per_user = meeting_1_2_1.to_f / total.to_f
        ceu_per_user = ceu.to_f / total.to_f
        v_per_user = v.to_f / total.to_f
      sheet.add_row [summary.departament.name,summary.id, tyfcb]
      sheet.add_row [summary.departament.name,summary.id, rgirgo]
      sheet.add_row [summary.departament.name,summary.id, sprintf('%.2f', rgirgo_per_user)]
      sheet.add_row [summary.departament.name,summary.id, meeting_1_2_1]
      sheet.add_row [summary.departament.name,summary.id, sprintf('%.2f', meeting_1_2_1_per_user)]
      sheet.add_row [summary.departament.name,summary.id, ceu]
      sheet.add_row [summary.departament.name,summary.id, sprintf('%.2f', ceu_per_user)]
      sheet.add_row [summary.departament.name, summary.id, v]
      sheet.add_row [summary.departament.name,summary.id, sprintf('%.2f', v_per_user)]
    end
end

So from the code we can see that I generate lots of tyfcb, ceu and etc variables. All of them are printed in new row. I want to to print all tyfcb variables in one row, all ceu variables in one row and etc. How should I do with axlsx gem? Thanks for answers.

A:

Use add_cell
add_cell(value = '', options = {}) ⇒ Cell

This adds a single cell to the row based on the data provided and updates the worksheet's autofit data.
http://www.rubydoc.info/github/randym/axlsx/Axlsx/Row

