summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjohnnyshields <[email protected]>2023-04-03 10:01:24 +0900
committerjohnnyshields <[email protected]>2023-04-03 10:01:24 +0900
commit467ac5cb9e03ff975929dd5bf473b75f7b6f1b6c (patch)
treea07acd22ebbc21766a3f810ce5b84acc5574ea48
parent98a26ea04e886ce6f712e4e97e6b9d09b4691bb6 (diff)
downloadcaxlsx-467ac5cb9e03ff975929dd5bf473b75f7b6f1b6c.tar.gz
caxlsx-467ac5cb9e03ff975929dd5bf473b75f7b6f1b6c.zip
Escape array formulas
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb5
-rw-r--r--test/workbook/worksheet/tc_cell.rb13
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index f0345705..39452c47 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -174,7 +174,8 @@ module Axlsx
!is_text_run? && # No inline styles
[email protected]? && # Not nil
[email protected]? && # Not empty
- [email protected]_with?(*FORMULA_PREFIXES) # Not a formula
+ !is_formula? && # Not a formula
+ !is_array_formula? # Not an array formula
end
# The inline font_name property for the cell
@@ -376,6 +377,8 @@ module Axlsx
end
def is_array_formula?
+ return false if escape_formulas
+
type == :string && @value.to_s.start_with?('{=') && @value.to_s.end_with?('}')
end
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index b8e16404..29f42c4f 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -318,6 +318,8 @@ class TestCell < Test::Unit::TestCase
end
def test_plain_string
+ @c.escape_formulas = false
+
@c.type = :integer
assert_equal(@c.plain_string?, false)
@@ -334,6 +336,17 @@ class TestCell < Test::Unit::TestCase
@c.value = '=sum'
assert_equal(@c.plain_string?, false)
+ @c.value = '{=sum}'
+ assert_equal(@c.plain_string?, false)
+
+ @c.escape_formulas = true
+
+ @c.value = '=sum'
+ assert_equal(@c.plain_string?, true)
+
+ @c.value = '{=sum}'
+ assert_equal(@c.plain_string?, true)
+
@c.value = 'plain string'
@c.font_name = 'Arial'
assert_equal(@c.plain_string?, false)