summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-01-13 18:56:38 +0900
committerRandy Morgan <[email protected]>2012-01-13 18:56:38 +0900
commitc3459ef98ee4ede887d28dfacd1c0d62e0cddd29 (patch)
tree17c04ff769676454f2d9ec40e1e615a63191014d
parentc16ba34f2165712f37470d127039beb8343f8cfe (diff)
downloadcaxlsx-c3459ef98ee4ede887d28dfacd1c0d62e0cddd29.tar.gz
caxlsx-c3459ef98ee4ede887d28dfacd1c0d62e0cddd29.zip
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
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb1
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb7
2 files changed, 8 insertions, 0 deletions
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]