From ff2085b7159cd5665d65c959ca2cd57f56ebfe6a Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Tue, 10 Apr 2012 11:16:53 +0900 Subject: 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. --- lib/axlsx/workbook/worksheet/worksheet.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib') 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)] -- cgit v1.2.3