ruby spreadsheet row background color

fflyer05 picture fflyer05 · Oct 11, 2011 · Viewed 8k times · Source

I am trying to parse an excel spreadsheet using "spreadsheet". How could I get the background color of each row?

Answer

okliv picture okliv · Feb 17, 2013
book = Spreadsheet::Workbook.new 
sheet = book.create_worksheet :name => 'Name'
format = Spreadsheet::Format.new :color=> :blue, :pattern_fg_color => :yellow, :pattern => 1
sheet.row(0).set_format(0, format) #for first cell in first row

or

sheet.row(0).default_format = format #for entire first row

you can iterate over each row/cell and apply style exactly where you want