diff options
| author | Randy Morgan <[email protected]> | 2012-09-07 09:35:46 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-09-07 09:35:46 +0900 |
| commit | ddc35f6629de2b1363b0d947b4a115344be4c0d1 (patch) | |
| tree | f6200eb7a1d0475c37a2337d72fb616b67f69c76 | |
| parent | df26c0c954d9a38255f536d0f9379921aa4bc526 (diff) | |
| download | caxlsx-ddc35f6629de2b1363b0d947b4a115344be4c0d1.tar.gz caxlsx-ddc35f6629de2b1363b0d947b4a115344be4c0d1.zip | |
properly recognize exponential values as float
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 3 |
4 files changed, 7 insertions, 2 deletions
@@ -10,3 +10,5 @@ example.csv *.*~ .DS_Store tmp +*.pem +*.pfx @@ -146,6 +146,8 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem, #Change log --------- - **September.??.12**: 1.2.3 + - fix exponential float/bigdecimal values rendering as strings intead + of 'numbers' in excel. - added support for :none option on chart axis labels - added support for paper_size option on worksheet.page_setup - **August.27.12**: 1.2.2 diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 7e0d7916..2846225f 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -380,7 +380,7 @@ module Axlsx :boolean elsif v.to_s.match(/\A[+-]?\d+?\Z/) #numeric :integer - elsif v.to_s.match(/\A[+-]?\d+\.\d+?\Z/) #float + elsif v.to_s.match(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/) #float :float else :string diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 9f425ec7..555fcff7 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -60,7 +60,7 @@ class TestCell < Test::Unit::TestCase assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array } assert_nothing_raised("type can be changed") { @c.type = :string } assert_equal(@c.value, "1.0", "changing type casts the value") - + assert_equal(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type') assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time') assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date') assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean') @@ -88,6 +88,7 @@ class TestCell < Test::Unit::TestCase assert_equal(@c.send(:cell_type_from_value, -1), :integer) assert_equal(@c.send(:cell_type_from_value, true), :boolean) assert_equal(@c.send(:cell_type_from_value, false), :boolean) + assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float) end def test_cast_value |
