lib/row.rb in surpass-0.0.3 vs lib/row.rb in surpass-0.0.4

- old
+ new

@@ -63,10 +63,11 @@ @min_col_index = a if a < @min_col_index @max_col_index = a if a > @max_col_index end end + # TODO can we get rid of this? Tests pass if it is commented out. def style=(style) adjust_height(style) @xf_index = @parent_wb.styles.add(style) @has_default_format = 1 end @@ -100,11 +101,34 @@ def cell(col_index) cells.select {|c| c.index == col_index}.first end def write(col, label, style) - style = StyleFormat.new(style) if style.is_a?(Hash) + case style + when StyleFormat + # leave it alone + when Hash + style = StyleFormat.new(style) +### @export "autoformats" + when TrueClass # Automatically apply a nice numeric format. + case label + when DateTime, Time + style = @parent_wb.styles.default_datetime_style + when Date + style = @parent_wb.styles.default_date_style + when Float + style = @parent_wb.styles.default_float_style + else + style = @parent_wb.styles.default_style + end +### @end + when NilClass + style = @parent_wb.styles.default_style + else + raise "I don't know how to use this to format a cell #{style.inspect}" + end + style_index = @parent_wb.styles.add(style) adjust_height(style) adjust_boundary_column_indexes(col) case label @@ -122,10 +146,10 @@ when Date, DateTime, Time @cells << NumberCell.new(self, col, style_index, as_excel_date(label)) when ExcelFormula @cells << FormulaCell.new(self, col, style_index, label) else - raise label.class.name + raise "You are trying to write an object of class #{label.class.name} to a spreadsheet. Please convert this to a supported class such as String." end end def write_blanks(c1, c2, style) raise unless c1 <= c2