diff options
| author | Randy Morgan <[email protected]> | 2012-01-13 18:56:38 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-01-13 18:56:38 +0900 |
| commit | c3459ef98ee4ede887d28dfacd1c0d62e0cddd29 (patch) | |
| tree | 17c04ff769676454f2d9ec40e1e615a63191014d | |
| parent | c16ba34f2165712f37470d127039beb8343f8cfe (diff) | |
| download | caxlsx-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.rb | 1 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 7 |
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] |
