Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RubyXL: How to add multiple cells of data to a worksheet?

How can I add an entire array of cells to a row? I have something like this->

w = RubyXL::Workbook.new
w.add_worksheet("Test")
test_sheet = w["Test"]
test_sheet.add_cell(0, 0, "abc") #this adds abc to row 0 and column 0

arr = ["hello","again","hi","there"]

Is there anything like

test_sheet.add_row(a)

where I can all all contents of array arr to one row in the Test worksheet with each element of a in a separate cell?

like image 620
KavitaC Avatar asked Nov 07 '22 02:11

KavitaC


1 Answers

Looks like there is no official way to do it. We use this code in our project:

row_index = sheet.sheet_data.rows.size
arr.each_with_index do |value, index|
  sheet.add_cell(row_index, index, value)
end
like image 58
proton Avatar answered Nov 15 '22 10:11

proton