simple_xlsx_reader 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f51a4ca0ca865cc2a9ddebeb72fa3db9cc3f309ce2d1a3d34a492f09e22789c
4
- data.tar.gz: 90a2b1ac9071fcef0797f5839652d919169cfcf6862de8926b7b605dcc53cd7e
3
+ metadata.gz: d60e969d7d2db69578d543b6ebab36d29b3e3e88b4d62d67d00218b09b644cc5
4
+ data.tar.gz: 36e12c7d95b6319f8f3bb565a1bc1b8eea6d1ca44928b3188a6892bf1f0c6513
5
5
  SHA512:
6
- metadata.gz: 38f0844bfa6e30cd9af9414057a767cc3bd7cf6ed11023a7306b18686ad3cb250a70191d9b77f8cbc2a590aaa24f822cbec6c546f667fe6e820bb356ddd369f9
7
- data.tar.gz: 69af022e15fa95404ab0208be1b4b6661ae14033c73477b98b78f01795712313d63952dce0674ba34ee3aecc19105ef28adfa708de738682583f3b672668a251
6
+ metadata.gz: 6610958e6cb393e6013d303dd541f80a19d91415f6ebbe1d03162b52580ac361ad3f7e8e9fef5904a1daae72fe0774a5a83f47617c75ac185748c78e2c828e5a
7
+ data.tar.gz: f556a9d31d48aa7cfeb0a1a9194736f2740ae3a2c868ed6a65fc197411351b28751d9caa72fd2bbbeb7eb22acd9ba0e2d53606f414bd36843f811ccb93d80ed2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 4.0.0
2
+
3
+ * Fix percentage rounding errors. Previously we were dividing by 100, when we
4
+ actually don't need to, so percentage types were 100x too small. Fixes #21.
5
+ Major bump because workarounds might have been implemented for previous
6
+ incorrect behavior.
7
+ * Fix small oddity in one currency format where round numbers would be cast
8
+ to an integer instead of a float.
9
+
1
10
  ### 3.0.1
2
11
 
3
12
  * Fix parsing "chunky" UTF-8 workbooks. Closes issues #39 and #45. See ce67f0d4.
@@ -103,7 +103,6 @@ module SimpleXlsxReader
103
103
  end
104
104
  end
105
105
 
106
-
107
106
  # For some reason I can't figure out in a reasonable timeframe,
108
107
  # SAX parsing some workbooks captures separate strings in the same cell
109
108
  # when we encounter UTF-8, although I can't get workbooks made in my
@@ -9,38 +9,39 @@ module SimpleXlsxReader
9
9
 
10
10
  # Map of non-custom numFmtId to casting symbol
11
11
  NumFmtMap = {
12
- 0 => :string, # General
13
- 1 => :fixnum, # 0
14
- 2 => :float, # 0.00
15
- 3 => :fixnum, # #,##0
16
- 4 => :float, # #,##0.00
17
- 5 => :unsupported, # $#,##0_);($#,##0)
18
- 6 => :unsupported, # $#,##0_);[Red]($#,##0)
19
- 7 => :unsupported, # $#,##0.00_);($#,##0.00)
20
- 8 => :unsupported, # $#,##0.00_);[Red]($#,##0.00)
21
- 9 => :percentage, # 0%
22
- 10 => :percentage, # 0.00%
23
- 11 => :bignum, # 0.00E+00
24
- 12 => :unsupported, # # ?/?
25
- 13 => :unsupported, # # ??/??
26
- 14 => :date, # mm-dd-yy
27
- 15 => :date, # d-mmm-yy
28
- 16 => :date, # d-mmm
29
- 17 => :date, # mmm-yy
30
- 18 => :time, # h:mm AM/PM
31
- 19 => :time, # h:mm:ss AM/PM
32
- 20 => :time, # h:mm
33
- 21 => :time, # h:mm:ss
34
- 22 => :date_time, # m/d/yy h:mm
35
- 37 => :unsupported, # #,##0 ;(#,##0)
36
- 38 => :unsupported, # #,##0 ;[Red](#,##0)
37
- 39 => :unsupported, # #,##0.00;(#,##0.00)
38
- 40 => :unsupported, # #,##0.00;[Red](#,##0.00)
39
- 45 => :time, # mm:ss
40
- 46 => :time, # [h]:mm:ss
41
- 47 => :time, # mmss.0
42
- 48 => :bignum, # ##0.0E+0
43
- 49 => :unsupported # @
12
+ 0 => :string, # General
13
+ 1 => :fixnum, # 0
14
+ 2 => :float, # 0.00
15
+ 3 => :fixnum, # #,##0
16
+ 4 => :float, # #,##0.00
17
+ 5 => :unsupported, # $#,##0_);($#,##0)
18
+ 6 => :unsupported, # $#,##0_);[Red]($#,##0)
19
+ 7 => :unsupported, # $#,##0.00_);($#,##0.00)
20
+ 8 => :unsupported, # $#,##0.00_);[Red]($#,##0.00)
21
+ 9 => :percentage, # 0%
22
+ 10 => :percentage, # 0.00%
23
+ 11 => :bignum, # 0.00E+00
24
+ 12 => :unsupported, # # ?/?
25
+ 13 => :unsupported, # # ??/??
26
+ 14 => :date, # mm-dd-yy
27
+ 15 => :date, # d-mmm-yy
28
+ 16 => :date, # d-mmm
29
+ 17 => :date, # mmm-yy
30
+ 18 => :time, # h:mm AM/PM
31
+ 19 => :time, # h:mm:ss AM/PM
32
+ 20 => :time, # h:mm
33
+ 21 => :time, # h:mm:ss
34
+ 22 => :date_time, # m/d/yy h:mm
35
+ 37 => :unsupported, # #,##0 ;(#,##0)
36
+ 38 => :unsupported, # #,##0 ;[Red](#,##0)
37
+ 39 => :unsupported, # #,##0.00;(#,##0.00)
38
+ 40 => :unsupported, # #,##0.00;[Red](#,##0.00)
39
+ 44 => :float, # some odd currency format ?from Office 2007?
40
+ 45 => :time, # mm:ss
41
+ 46 => :time, # [h]:mm:ss
42
+ 47 => :time, # mmss.0
43
+ 48 => :bignum, # ##0.0E+0
44
+ 49 => :unsupported # @
44
45
  }.freeze
45
46
 
46
47
  def parse
@@ -162,7 +162,7 @@ module SimpleXlsxReader
162
162
  when :float
163
163
  value.to_f
164
164
  when :percentage
165
- value.to_f / 100
165
+ value.to_f
166
166
  # the trickiest. note that all these formats can vary on
167
167
  # whether they actually contain a date, time, or datetime.
168
168
  when :date, :time, :date_time
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleXlsxReader
4
- VERSION = '3.0.1'
4
+ VERSION = '4.0.0'
5
5
  end
Binary file
@@ -1015,4 +1015,21 @@ describe SimpleXlsxReader do
1015
1015
  )
1016
1016
  end
1017
1017
  end
1018
+
1019
+ describe 'when using percentages & currencies' do
1020
+ let(:pnc_path) do
1021
+ # This file provided by a GitHub user having parse errors in these fields
1022
+ File.join(File.dirname(__FILE__), 'percentages_n_currencies.xlsx')
1023
+ end
1024
+
1025
+ let(:sheet) { SimpleXlsxReader.open(pnc_path).sheets[0] }
1026
+
1027
+ it 'reads percentages as floats of the form 0.XX' do
1028
+ _(sheet.rows.slurp[1][2]).must_equal(0.87)
1029
+ end
1030
+
1031
+ it 'reads currencies as floats' do
1032
+ _(sheet.rows.slurp[1][4]).must_equal(300.0)
1033
+ end
1034
+ end
1018
1035
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_xlsx_reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Woody Peterson
@@ -115,6 +115,7 @@ files:
115
115
  - test/lower_case_sharedstrings.xlsx
116
116
  - test/lower_case_sharedstrings_test.rb
117
117
  - test/misc_numbers.xlsx
118
+ - test/percentages_n_currencies.xlsx
118
119
  - test/performance_test.rb
119
120
  - test/sesame_street_blog.xlsx
120
121
  - test/shared_strings.xml
@@ -156,6 +157,7 @@ test_files:
156
157
  - test/lower_case_sharedstrings.xlsx
157
158
  - test/lower_case_sharedstrings_test.rb
158
159
  - test/misc_numbers.xlsx
160
+ - test/percentages_n_currencies.xlsx
159
161
  - test/performance_test.rb
160
162
  - test/sesame_street_blog.xlsx
161
163
  - test/shared_strings.xml