Unable to format cell after merging the cell

Showing 1-2 of 2 messages
Unable to format cell after merging the cell Shail 7/5/12 12:07 AM
Hi Guys,


I m a newbie in RoR world.... Was trying to make a excel sheet using ruby.

I just want to know How to format the merge cells?

Thanks in advance.

-Shail
Re: Unable to format cell after merging the cell randym 7/5/12 1:30 AM
Hi Shail

You need to populate the cells in your worksheet and apply the styles you want the cells to have. I've found this quite annoying with MS Excel as LibraOffice handles sparse sheets perfectly. 

If you look at the example below, you will notice that "" is being pushed into the empty cells that will be merged, and the style is applied to those cells as well.

#```ruby
wb.add_worksheet(:name => 'Merging Cells') do |sheet|
  # cell level style overides when adding cells
  sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
  sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
  sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
  sheet.merge_cells("A4:C4")
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
  sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
end
#```

Does that help at all?