From e14682fb484cd72ba5f479cc1f7d46a7a9fd6007 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Tue, 15 Jan 2013 21:53:03 +0900 Subject: Added support for iso 8601 data types. Not really sure what excel is going to do with these data types, but hooking it up is the first step ;) --- lib/axlsx/workbook/worksheet/cell.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 7617bb0f..abd60661 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -81,7 +81,7 @@ module Axlsx attr_reader :type # @see type def type=(v) - RestrictionValidator.validate "Cell.type", [:date, :time, :float, :integer, :string, :boolean], v + RestrictionValidator.validate "Cell.type", [:date, :time, :float, :integer, :string, :boolean, :iso_8601], v @type=v self.value = @value unless @value.nil? end @@ -373,6 +373,11 @@ module Axlsx :integer elsif v.to_s =~ /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/ #float :float + # \A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9]) + # T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)? + # (Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z + elsif v.to_s =~/\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z/ + :iso_8601 else :string end @@ -396,6 +401,9 @@ module Axlsx v.to_i elsif @type == :boolean v ? 1 : 0 + elsif @type == :iso_8601 + #consumer is responsible for ensuring the iso_8601 format when specifying this type + v else @type = :string # TODO find a better way to do this as it accounts for 30% of -- cgit v1.2.3