From 376d60eebeb0a48579862004d8a70b00fb39ee32 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Sat, 2 Jun 2012 23:52:32 +0900 Subject: more work on solidifying parsing of data caching for charts to eliminate formula strings. --- README.md | 2 ++ lib/axlsx/drawing/num_data.rb | 4 ++-- lib/axlsx/drawing/num_val.rb | 2 +- lib/axlsx/workbook/worksheet/cell.rb | 4 ++++ test/drawing/tc_num_data.rb | 6 +++++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 38c760ea..48f501ba 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ The example listing is getting overly large to maintain here. If you are using Yard, you will be able to see the examples in line below. If not, please refer to the Please see the {file:examples/example.rb} file. +![examples](https://github.com/randym/axlsx/raw/master/examples/examples.rb) + {include:file:examples/example.rb} There is much, much more you can do with this gem. If you get stuck, grab me on IRC or submit an issue to GitHub. Chances are that it has already been implemented. If it hasn't - let's take a look at adding it in. diff --git a/lib/axlsx/drawing/num_data.rb b/lib/axlsx/drawing/num_data.rb index 802a0216..ee6b145e 100644 --- a/lib/axlsx/drawing/num_data.rb +++ b/lib/axlsx/drawing/num_data.rb @@ -25,8 +25,8 @@ module Axlsx def data=(values=[]) @tag_name = values.first.is_a?(Cell) ? :numCache : :numLit values.each do |value| - v = value.is_a?(Cell) ? value.value : value - @pt << NumVal.new(:v => v) + value = value.is_formula? ? 0 : value.value if value.is_a?(Cell) + @pt << NumVal.new(:v => value) end end diff --git a/lib/axlsx/drawing/num_val.rb b/lib/axlsx/drawing/num_val.rb index 35dbdb83..ed655732 100644 --- a/lib/axlsx/drawing/num_val.rb +++ b/lib/axlsx/drawing/num_val.rb @@ -26,7 +26,7 @@ module Axlsx # serialize the object def to_xml_string(idx, str = "") Axlsx::validate_unsigned_int(idx) - str << '' << v.to_s.to_i.to_s << '' + str << '' << v.to_s << '' end end end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 745809f9..e3e153e0 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -317,6 +317,10 @@ module Axlsx str << '' end + def is_formula? + @type == :string && @value.start_with('=') + end + private # Utility method for setting inline style attributes diff --git a/test/drawing/tc_num_data.rb b/test/drawing/tc_num_data.rb index 85bf5614..2549af4d 100644 --- a/test/drawing/tc_num_data.rb +++ b/test/drawing/tc_num_data.rb @@ -9,7 +9,11 @@ class TestNumData < Test::Unit::TestCase def test_initialize assert_equal(@num_data.format_code, "General") end - + + def test_formula_based_cell + + end + def test_format_code assert_raise(ArgumentError) {@num_data.format_code = 7} assert_nothing_raised {@num_data.format_code = 'foo_bar'} -- cgit v1.2.3