summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-05-12 00:34:11 +0900
committerRandy Morgan <[email protected]>2012-05-12 00:34:11 +0900
commit88b67ba036c038be9d2cb116bb70eac720f3e40b (patch)
tree8f760b13cb257fb07c910a9805d167b97a9e50be
parentac0600f12fb15d1b3fe0cce1ca7a2dced4cf5285 (diff)
downloadcaxlsx-88b67ba036c038be9d2cb116bb70eac720f3e40b.tar.gz
caxlsx-88b67ba036c038be9d2cb116bb70eac720f3e40b.zip
patch formula parsing.
#92 many thanks to @alexei-lexx for not only finding this, but taking time to report the problem.
-rw-r--r--lib/axlsx.rb1
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb2
-rw-r--r--test/workbook/worksheet/tc_cell.rb10
3 files changed, 12 insertions, 1 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index 6fce32b5..6e8f4e23 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -54,6 +54,7 @@ module Axlsx
ref
end
+ # returns the x, y position of a cell
def self.name_to_indices(name)
raise ArgumentError, 'invalid cell name' unless name.size > 1
v = name[/[A-Z]+/].reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 91efa8d9..c58ede3a 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -296,7 +296,7 @@ module Axlsx
when :string
#parse formula
if @value.start_with?('=')
- str << 't="str"><f>' << @value.to_s.gsub('=', '') << '</f>'
+ str << 't="str"><f>' << @value.to_s.sub('=', '') << '</f>'
else
#parse shared
if @ssti
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index edb3ae85..6a93fc58 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -251,6 +251,16 @@ class TestCell < Test::Unit::TestCase
assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
end
+ def test_to_xml_string_formula
+ p = Axlsx::Package.new
+ ws = p.workbook.add_worksheet do |ws|
+ ws.add_row ["=IF(2+2=4,4,5)"]
+ end
+ doc = Nokogiri::XML(ws.to_xml_string)
+ assert("//f[text()=['IF(2+2=4,4,5)']")
+
+ end
+
def test_to_xml
# TODO This could use some much more stringent testing related to the xml content generated!
row = @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)"]