Unable to format cell after merging the cell

127 views
Skip to first unread message

Shail

unread,
Jul 5, 2012, 3:07:51 AM7/5/12
to ax...@googlegroups.com
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

randym

unread,
Jul 5, 2012, 4:30:50 AM7/5/12
to ax...@googlegroups.com
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?
Reply all
Reply to author
Forward
0 new messages