Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging cells with Ruby Gem Spreadsheet

How do I merge cells using the Ruby Spreadsheet gem. I would like to merge the first 6 cells on the first row of a worksheet. When I try the following it does not work:

merge_format = Spreadsheet::Format.new :align => :merge
6.times do |j|
  sheet.row(0).set_format(j,merge_format)
end

What am I doing wrong?

like image 817
John Avatar asked Jul 22 '12 19:07

John


1 Answers

You can simply do

sheet.merge_cells(start_row, start_col, end_row, end_col)

If you want to go with set_format, I'd advise trying :vertical_align => :merge, although I didn't use it since merge_cells always worked for me.

like image 72
HargrimmTheBleak Avatar answered Oct 11 '22 13:10

HargrimmTheBleak