From c3459ef98ee4ede887d28dfacd1c0d62e0cddd29 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Fri, 13 Jan 2012 18:56:38 +0900 Subject: applying col_style to a list of rows of unequal length can cause an error as there is no cell at the index. for example, with a structure like this: ******** ** ******** *** col_style 2, 1 would fail as the second row has no cell at index 2. Thanks Don! https://github.com/randym/axlsx/issues/15 --- lib/axlsx/workbook/worksheet/worksheet.rb | 1 + test/workbook/worksheet/tc_worksheet.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 41d0f841..8b0f8bfa 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -195,6 +195,7 @@ module Axlsx offset = options.delete(:row_offset) || 0 @rows[(offset..-1)].each do |r| cells = r.cells[index] + next unless cells if cells.is_a?(Array) cells.each { |c| c.style = style } else diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index 4722a999..24e26155 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -69,6 +69,13 @@ class TestWorksheet < Test::Unit::TestCase assert_equal(@ws.rows.first.cells[0].style, 0) end + def test_col_style_with_empty_column + @ws.add_row [1,2,3,4] + @ws.add_row [1] + @ws.add_row [1,2,3,4] + assert_nothing_raised {@ws.col_style(1, 1)} + end + def test_cols @ws.add_row [1,2,3,4] @ws.add_row [1,2,3,4] -- cgit v1.2.3