summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2013-01-15 21:53:03 +0900
committerRandy Morgan <[email protected]>2013-01-15 21:53:03 +0900
commite14682fb484cd72ba5f479cc1f7d46a7a9fd6007 (patch)
treefd5a6efd273caebcb5ad4e6be66d0639e37cfcc7 /lib
parentbd099af6f8fe954eabc1db33c9ad3990629ddff1 (diff)
downloadcaxlsx-e14682fb484cd72ba5f479cc1f7d46a7a9fd6007.tar.gz
caxlsx-e14682fb484cd72ba5f479cc1f7d46a7a9fd6007.zip
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 ;)
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb10
1 files changed, 9 insertions, 1 deletions
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