It is possible to apply a font color to individual cells, without creating a style:
Axlsx::Package.new do |p|
p.workbook.add_worksheet(:name => "test") do |ws|
ws.add_row ["a", "b", "c"]
ws.add_row ["d", "e", "f"]
ws.add_row ["g", "h", "i"]
ws.rows.each do |r|
r.cells.each do |c|
c.color = "009900"
if ['a', 'e', 'i'].include?(c.value)
c.color = "009900" // how can I do the same for background color?
end
end
end
end
p.serialize('test.xlsx')
end
It is possible to apply a style to individual cells:
Axlsx::Package.new do |p|
p.workbook.add_worksheet(:name => "test") do |ws|
style1 = ws.styles.add_style( :bg_color => "FFFFFF00")
ws.add_row ["a", "b", "c"]
ws.add_row ["d", "e", "f"]
ws.add_row ["g", "h", "i"]
ws.rows.each do |r|
r.cells.each do |c|
if ['a', 'e', 'i'].include?(c.value)
c.style = style1
end
end
end
end
p.serialize('test.xlsx')
end
but in my case this is impractical, as I would like to have the cell background be a function of the cell value and would like to avoid building hundreds or thousands of styles.
Any suggestions?