summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJurriaan Pruis <[email protected]>2014-03-04 18:39:19 +0100
committerJurriaan Pruis <[email protected]>2014-03-04 18:39:19 +0100
commit39b700add2fd0920a61f6951a6466f15da355edb (patch)
tree4c7271e21de1bd079c7ae61f748c914282405251 /lib
parente8ec96f28c69443ce1133ccb7d60d0019669623e (diff)
parent277f491501084673da580ce750712ed5fb81970a (diff)
downloadcaxlsx-39b700add2fd0920a61f6951a6466f15da355edb.tar.gz
caxlsx-39b700add2fd0920a61f6951a6466f15da355edb.zip
Merge pull request #295 from tafryn/arrayformula
Added array formula support
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/cell_serializer.rb13
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index a0607e26..8dec8e92 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -328,6 +328,10 @@ module Axlsx
type == :string && @value.to_s.start_with?(?=)
end
+ def is_array_formula?
+ type == :string && @value.to_s.start_with?('{=') && @value.to_s.end_with?('}')
+ end
+
# returns the absolute or relative string style reference for
# this cell.
# @param [Boolean] absolute -when false a relative reference will be
diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb
index 0f66c53e..81ae11de 100644
--- a/lib/axlsx/workbook/worksheet/cell_serializer.rb
+++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -95,6 +95,15 @@ module Axlsx
str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
end
+ # Serializes cells that are type array formula
+ # @param [Cell] cell The cell that is being serialized
+ # @param [String] str The string the serialized content will be appended to.
+ # @return [String]
+ def array_formula_serialization(cell, str='')
+ str << ('t="str">' << '<f t="array" ref="' << cell.r << '">' << cell.value.to_s.sub('{=', '').sub(/}$/, '') << '</f>')
+ str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
+ end
+
# Serializes cells that are type inline_string
# @param [Cell] cell The cell that is being serialized
# @param [String] str The string the serialized content will be appended to.
@@ -110,7 +119,9 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def string(cell, str='')
- if cell.is_formula?
+ if cell.is_array_formula?
+ array_formula_serialization cell, str
+ elsif cell.is_formula?
formula_serialization cell, str
elsif !cell.ssti.nil?
value_serialization 's', cell.ssti, str