6

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?

John
  • 13,125
  • 14
  • 52
  • 73

1 Answers1

21

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.

HargrimmTheBleak
  • 2,147
  • 1
  • 19
  • 19
  • Thanks! BTW, where did you find that method? I could not find it on http://spreadsheet.rubyforge.org/GUIDE_txt.html – John Jul 22 '12 at 19:46
  • I was browsing sources actually looking for the same answer :) The fact that it's undocumented might leave a chance that they change or remove the API, but I still found it convenient to use. – HargrimmTheBleak Jul 23 '12 at 04:21
  • Thanks! It's been like two years and it's still not in the docs... (sigh) – yekta Jun 05 '14 at 19:10