From 87cd49d0b8ab08c251368e89cdd9cb1f1eedbd4e Mon Sep 17 00:00:00 2001 From: tafryn Date: Mon, 3 Mar 2014 16:29:06 -0800 Subject: Add support for array formulas. --- lib/axlsx/workbook/worksheet/cell.rb | 4 ++++ lib/axlsx/workbook/worksheet/cell_serializer.rb | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'lib') 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 << ('' << cell.formula_value.to_s << '') 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">' << '' << cell.value.to_s.sub('{=', '').sub(/}$/, '') << '') + str << ('' << cell.formula_value.to_s << '') 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 -- cgit v1.2.3