From 3d4ead0e516d718a7f79373b6e4d17e2813921bd Mon Sep 17 00:00:00 2001 From: sato-s Date: Fri, 7 Oct 2016 01:11:18 +0900 Subject: set color with Row#color= --- lib/axlsx/workbook/worksheet/row.rb | 7 +++++++ test/workbook/worksheet/tc_row.rb | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb index 078e281f..b394279f 100644 --- a/lib/axlsx/workbook/worksheet/row.rb +++ b/lib/axlsx/workbook/worksheet/row.rb @@ -103,6 +103,13 @@ module Axlsx c end + # sets the color for every cell in this row + def color=(color) + each_with_index do | cell, index | + cell.color = color.is_a?(Array) ? color[index] : color + end + end + # sets the style for every cell in this row def style=(style) each_with_index do | cell, index | diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb index 808e0138..43e7d23f 100644 --- a/test/workbook/worksheet/tc_row.rb +++ b/test/workbook/worksheet/tc_row.rb @@ -27,6 +27,11 @@ class TestRow < Test::Unit::TestCase r.cells.each { |c| assert_equal(c.style,1) } end + def test_color + r = @ws.add_row([1,2,3,4,5]) + r.color = "FF00FF00" + r.cells.each { |c| assert_equal(c.color.rgb, "FF00FF00") } + end def test_index assert_equal(@row.row_index, @row.worksheet.rows.index(@row)) -- cgit v1.2.3