simple_xlsx_reader 2.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20c74bef372629ffb807d50df274c90682e17d53eed296a1e05fbb99533d4a8e
4
- data.tar.gz: 9c4311913e79ad139414a4fe064d89fb246a1d46f30b7736c87f049985801660
3
+ metadata.gz: 5449525d4e46a013f92e8406a2ec2d07b06bb795efc7c8d76b9ffbcace22a38f
4
+ data.tar.gz: 5c664baa8d88692767f5bb6d2879e24c27098206695b88da42f3bc0d30bb9bce
5
5
  SHA512:
6
- metadata.gz: 18db8595a36d4d9bb0f1dfee5da58753b799a6358530dfb9436f9c7b72e8e06bb9101d86d8dc617669c075fced44db8c24fdca6c5a3b2cb6b908cc0cd645eeb1
7
- data.tar.gz: 23d4b057060c5f66ad3d57d0d65fa6e127ed4c7faa622ec0d236b58dd439179b41dff041ec2dd955c2ec893d577d9660465d2dcea0fe9a9f3af5e911ac5aa8e7
6
+ metadata.gz: 90d5fedde0aa4cc2bcb8b4d9134859890bbf4357efbf6ba9aa0aaf3bd21ad1cd9f54a279d1126938a300dee36fbb8a10d63b66f945c9f7eeb8edc880bb23327a
7
+ data.tar.gz: ab684cc09075a0b9a1054c045bf4202718159b258c87f62b10e18aafa4faaa7a527ba95f8e765f7609ab7ba24c43a31176906ecefd612c85badbdefee9164184
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ### 3.0.0
2
+
3
+ * Change the way we typecast cells in the General format. This probably won't
4
+ break anything in your app, but it's a change in behavior that theoretically
5
+ could.
6
+
7
+ Previously, we were treating cells using General the format as strings, when
8
+ according to the Office XML standard, they should be treated as numbers. We
9
+ now attempt to cast such cells as numbers, and fall back to strings if number
10
+ casting fails.
11
+
12
+ Thanks @jrodrigosm
13
+
1
14
  ### 2.0.1
2
15
 
3
16
  * Restore ability to parse IO strings (@robbevp)
@@ -149,7 +149,13 @@ module SimpleXlsxReader
149
149
  # detected earlier and cast here by its standardized symbol
150
150
  ##
151
151
 
152
- when :string, :unsupported
152
+ # no type encoded with the the General format defaults to a number type
153
+ when nil, :string
154
+ retval = Integer(value, exception: false)
155
+ retval ||= Float(value, exception: false)
156
+ retval ||= value
157
+ retval
158
+ when :unsupported
153
159
  value
154
160
  when :fixnum
155
161
  value.to_i
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleXlsxReader
4
- VERSION = '2.0.1'
4
+ VERSION = '3.0.0'
5
5
  end
Binary file
@@ -827,6 +827,10 @@ describe SimpleXlsxReader do
827
827
  <c r='I1' s='0'>
828
828
  <v>GUI-made hyperlink</v>
829
829
  </c>
830
+
831
+ <c r='J1' s='0'>
832
+ <v>1</v>
833
+ </c>
830
834
  </row>
831
835
  </sheetData>
832
836
 
@@ -925,6 +929,10 @@ describe SimpleXlsxReader do
925
929
  )
926
930
  )
927
931
  end
932
+
933
+ it "reads 'Generic' cells with numbers as numbers" do
934
+ _(@row[9]).must_equal 1
935
+ end
928
936
  end
929
937
 
930
938
  describe 'parsing documents with blank rows' do
@@ -936,7 +944,7 @@ describe SimpleXlsxReader do
936
944
  <sheetData>
937
945
  <row r="2" spans="1:1">
938
946
  <c r="A2" s="0">
939
- <v>0</v>
947
+ <v>a</v>
940
948
  </c>
941
949
  </row>
942
950
  <row r="4" spans="1:1">
@@ -967,13 +975,30 @@ describe SimpleXlsxReader do
967
975
  it 'reads row data despite gaps in row numbering' do
968
976
  _(@rows).must_equal [
969
977
  [nil, nil, nil, nil],
970
- ['0', nil, nil, nil],
978
+ ['a', nil, nil, nil],
971
979
  [nil, nil, nil, nil],
972
- [nil, '1', nil, nil],
973
- [nil, nil, '2', nil],
980
+ [nil, 1, nil, nil],
981
+ [nil, nil, 2, nil],
974
982
  [nil, nil, nil, nil],
975
- [nil, nil, nil, '3']
983
+ [nil, nil, nil, 3]
976
984
  ]
977
985
  end
978
986
  end
987
+
988
+ # https://support.microsoft.com/en-us/office/available-number-formats-in-excel-0afe8f52-97db-41f1-b972-4b46e9f1e8d2
989
+ describe 'numeric fields styled as "General"' do
990
+ let(:misc_numbers_path) do
991
+ File.join(File.dirname(__FILE__), 'misc_numbers.xlsx')
992
+ end
993
+
994
+ let(:sheet) { SimpleXlsxReader.open(misc_numbers_path).sheets[0] }
995
+
996
+ it 'reads medium sized integers as integers' do
997
+ _(sheet.rows.slurp[1][0]).must_equal 98070
998
+ end
999
+
1000
+ it 'reads large (>12 char) integers as integers' do
1001
+ _(sheet.rows.slurp[1][1]).must_equal 1234567890123
1002
+ end
1003
+ end
979
1004
  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: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Woody Peterson
@@ -113,6 +113,7 @@ files:
113
113
  - test/gdocs_sheet_test.rb
114
114
  - test/lower_case_sharedstrings.xlsx
115
115
  - test/lower_case_sharedstrings_test.rb
116
+ - test/misc_numbers.xlsx
116
117
  - test/performance_test.rb
117
118
  - test/sesame_street_blog.xlsx
118
119
  - test/shared_strings.xml
@@ -152,6 +153,7 @@ test_files:
152
153
  - test/gdocs_sheet_test.rb
153
154
  - test/lower_case_sharedstrings.xlsx
154
155
  - test/lower_case_sharedstrings_test.rb
156
+ - test/misc_numbers.xlsx
155
157
  - test/performance_test.rb
156
158
  - test/sesame_street_blog.xlsx
157
159
  - test/shared_strings.xml