simple_xlsx_reader 0.9.4 → 0.9.5
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.
- data/CHANGELOG.md +14 -0
- data/lib/simple_xlsx_reader.rb +4 -1
- data/lib/simple_xlsx_reader/version.rb +1 -1
- data/test/simple_xlsx_reader_test.rb +59 -27
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
### 0.9.5
|
2
|
+
|
3
|
+
* Fix inlineStr support (broken by formula support commit)
|
4
|
+
|
5
|
+
### 0.9.4
|
6
|
+
|
7
|
+
* Formula support. Formulas used to cause things to blow up, now they don't!
|
8
|
+
* Support number types styled as dates. Previously, the type was honored
|
9
|
+
above the style, which is incorrect for dates; date-numbers now parse as
|
10
|
+
dates.
|
11
|
+
* Error-free parsing of empty sheets
|
12
|
+
* Fix custom styles w/ numFmtId == 164. Custom style types are delineated
|
13
|
+
starting *at* numFmtId 164, not greater than 164.
|
14
|
+
|
1
15
|
### 0.9.3
|
2
16
|
|
3
17
|
* Support 1.8.7 (tests pass). Ongoing support will depend on ease.
|
data/lib/simple_xlsx_reader.rb
CHANGED
@@ -133,8 +133,11 @@ module SimpleXlsxReader
|
|
133
133
|
style = xcell.attributes['s'] &&
|
134
134
|
style_types[xcell.attributes['s'].value.to_i]
|
135
135
|
|
136
|
+
xvalue = type == 'inlineStr' ?
|
137
|
+
xcell.at_xpath('xmlns:is/xmlns:t') : xcell.at_xpath('xmlns:v')
|
138
|
+
|
136
139
|
cells << begin
|
137
|
-
self.class.cast(
|
140
|
+
self.class.cast(xvalue.text.strip, type, style, :shared_strings => shared_strings)
|
138
141
|
rescue => e
|
139
142
|
if !SimpleXlsxReader.configuration.catch_cell_load_errors
|
140
143
|
error = CellLoadError.new(
|
@@ -33,8 +33,8 @@ describe SimpleXlsxReader do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'reads type inlineStr as a string' do
|
36
|
-
|
37
|
-
|
36
|
+
described_class.cast('the value', nil, 'inlineStr').
|
37
|
+
must_equal 'the value'
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'reads date styles' do
|
@@ -154,6 +154,7 @@ describe SimpleXlsxReader do
|
|
154
154
|
XML
|
155
155
|
)
|
156
156
|
end
|
157
|
+
|
157
158
|
let(:xml) do
|
158
159
|
SimpleXlsxReader::Document::Xml.new.tap do |xml|
|
159
160
|
xml.sheets = [sheet]
|
@@ -217,14 +218,14 @@ describe SimpleXlsxReader do
|
|
217
218
|
end
|
218
219
|
end
|
219
220
|
|
220
|
-
it 'raises if configuration.
|
221
|
+
it 'raises if configuration.catch_cell_load_errors' do
|
221
222
|
SimpleXlsxReader.configuration.catch_cell_load_errors = false
|
222
223
|
|
223
224
|
lambda { described_class.new(xml).parse_sheet('test', xml.sheets.first) }.
|
224
225
|
must_raise(SimpleXlsxReader::CellLoadError)
|
225
226
|
end
|
226
227
|
|
227
|
-
it 'records a load error if not configuration.
|
228
|
+
it 'records a load error if not configuration.catch_cell_load_errors' do
|
228
229
|
SimpleXlsxReader.configuration.catch_cell_load_errors = true
|
229
230
|
|
230
231
|
sheet = described_class.new(xml).parse_sheet('test', xml.sheets.first)
|
@@ -232,24 +233,30 @@ describe SimpleXlsxReader do
|
|
232
233
|
end
|
233
234
|
end
|
234
235
|
|
235
|
-
describe '
|
236
|
+
describe 'parsing types' do
|
236
237
|
let(:xml) do
|
237
238
|
SimpleXlsxReader::Document::Xml.new.tap do |xml|
|
238
239
|
xml.sheets = [Nokogiri::XML(
|
239
240
|
<<-XML
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
241
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
242
|
+
<dimension ref="A1:C1" />
|
243
|
+
<sheetData>
|
244
|
+
<row>
|
245
|
+
<c r='A1' s='0'>
|
246
|
+
<v>Cell A1</v>
|
247
|
+
</c>
|
248
|
+
<c r='C1' s='1'>
|
249
|
+
<v>2.4</v>
|
250
|
+
</c>
|
251
|
+
<c r='D1' s='14'>
|
252
|
+
<v>01-06-84</v>
|
253
|
+
</c>
|
254
|
+
<c r='E1' t='inlineStr' s='0'>
|
255
|
+
<is><t>Cell E1</t></is>
|
256
|
+
</c>
|
257
|
+
</row>
|
258
|
+
</sheetData>
|
259
|
+
</worksheet>
|
253
260
|
XML
|
254
261
|
)]
|
255
262
|
|
@@ -257,19 +264,44 @@ describe SimpleXlsxReader do
|
|
257
264
|
# which is in this case 'General' type
|
258
265
|
xml.styles = Nokogiri::XML(
|
259
266
|
<<-XML
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
267
|
+
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
268
|
+
<cellXfs count="1">
|
269
|
+
<xf numFmtId="0" />
|
270
|
+
<xf numFmtId="2" />
|
271
|
+
<xf numFmtId="14" />
|
272
|
+
</cellXfs>
|
273
|
+
</styleSheet>
|
265
274
|
XML
|
266
275
|
)
|
267
276
|
end
|
268
|
-
end
|
269
277
|
|
270
|
-
|
271
|
-
|
272
|
-
|
278
|
+
before do
|
279
|
+
@rows = described_class.new(xml).parse_sheet('test', xml.sheets.first).rows
|
280
|
+
end
|
281
|
+
|
282
|
+
it "reads 'Generic' cells as strings" do
|
283
|
+
@rows[0].must_equal "Cell A1"
|
284
|
+
end
|
285
|
+
|
286
|
+
it "reads empty 'Generic' cells as nil" do
|
287
|
+
@rows[1].must_equal nil
|
288
|
+
end
|
289
|
+
|
290
|
+
# We could expand on these type tests, but really just a couple
|
291
|
+
# demonstrate that it's wired together. Type-specific tests should go
|
292
|
+
# on #cast
|
293
|
+
|
294
|
+
it "reads floats" do
|
295
|
+
@rows[2].must_equal 2.4
|
296
|
+
end
|
297
|
+
|
298
|
+
it "reads dates" do
|
299
|
+
@rows[3].must_equal Date.parse('Jan 6, 1984')
|
300
|
+
end
|
301
|
+
|
302
|
+
it "reads strings formatted as inlineStr" do
|
303
|
+
@rows[4].must_equal 'Cell E1'
|
304
|
+
end
|
273
305
|
end
|
274
306
|
end
|
275
307
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: simple_xlsx_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Woody Peterson
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|