diff options
| author | Randy Morgan <[email protected]> | 2012-04-10 11:16:53 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-10 11:16:53 +0900 |
| commit | ff2085b7159cd5665d65c959ca2cd57f56ebfe6a (patch) | |
| tree | aa378e0a53550de9b2d212442eef1ab8982522bf | |
| parent | c5abe63eee3f1435473afcbdbdea7990caef7bf3 (diff) | |
| download | caxlsx-ff2085b7159cd5665d65c959ca2cd57f56ebfe6a.tar.gz caxlsx-ff2085b7159cd5665d65c959ca2cd57f56ebfe6a.zip | |
Fix Dimension to check for nil members in rows.
Fix column_widhts to allow adding new columns that may not exist in the worksheet yet.
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 10 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 1 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 7aa38866..41b3cb73 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -147,7 +147,9 @@ module Axlsx # but at least a few other document readers expect this for conversion # @return [String] the A1:B2 style reference for the first and last row column intersection in the workbook def dimension - "#{rows.first.cells.first.r}:#{rows.last.cells.last.r}" + dim_start = rows.first.cells.first == nil ? 'A1' : rows.first.cells.first.r + dim_end = rows.last.cells.last == nil ? 'AA:200' : rows.last.cells.last.r + "#{dim_start}:#{dim_end}" end # Indicates if gridlines should be shown in the sheet. @@ -342,8 +344,8 @@ module Axlsx # @param [Integer|Float|Fixnum|nil] values def column_widths(*args) args.each_with_index do |value, index| - raise ArgumentError, "Invalid column specification" unless index < @column_info.size Axlsx::validate_unsigned_numeric(value) unless value == nil + @column_info[index] ||= Col.new index+1, index+1 @column_info[index].width = value end end @@ -456,13 +458,15 @@ module Axlsx styles = self.workbook.styles cellXfs, fonts = styles.cellXfs, styles.fonts sz = 11 + cells.each_with_index do |cell, index| @column_info[index] ||= Col.new index+1, index+1 col = @column_info[index] width = widths[index] col.width = width if [Integer, Float, Fixnum].include?(width.class) c_style = style[index] if [Integer, Fixnum].include?(style[index].class) - next if width == :ignore || col.width || (cell.value.is_a?(String) && cell.value.start_with?('=')) + #BUG - col.width wil only be nil the first time the column object is created. Subsequent row adds will not update the width of the column! col.width || + next if width == :ignore || col.width || (cell.value.is_a?(String) && cell.value.start_with?('=')) if self.workbook.use_autowidth cell_xf = cellXfs[(c_style || 0)] font = fonts[(cell_xf.fontId || 0)] diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index 320561b3..0d5fbb1a 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -307,7 +307,6 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row ["chasing windmills", "penut"] @ws.column_widths nil, 0.5 assert_equal(@ws.column_info[1].width, 0.5, 'eat my width') - assert_raise(ArgumentError, 'reject invalid columns') { @ws.column_widths 2, 7, nil } assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 } assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" } end |
