saxlsx 1.4.0 → 1.5.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 +4 -4
- data/.travis.yml +2 -1
- data/README.md +18 -14
- data/lib/saxlsx/file_system.rb +4 -4
- data/lib/saxlsx/rows_collection.rb +15 -1
- data/lib/saxlsx/rows_collection_parser.rb +11 -8
- data/lib/saxlsx/sax_parser.rb +3 -3
- data/lib/saxlsx/version.rb +1 -1
- data/saxlsx.gemspec +2 -0
- data/spec/benchmarks.rb +1 -1
- data/spec/data/SpecNumberFormat.xlsx +0 -0
- data/spec/sheet_spec.rb +28 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 597206ffbcc440bed3d0972489b4027464993b91
|
4
|
+
data.tar.gz: 2286d59b75e1641f1ed47e927a25d612c7891111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d5d8e6b1e6e29e2fbcc28b40bd9ce91a9d10d56b40fc15a56ca73a6a002eca850e875f977c2d8a9f01ed4df11affafae1762205aac35a613762085515ee3a1
|
7
|
+
data.tar.gz: 9dffa50378a9f632982978496fdd1d959990e6c9836d280b7e7dff43980b4f8edbf43a1d5694690986b90b8c523d36b47388675234d640f7558e17cfed247894
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -48,26 +48,30 @@ end
|
|
48
48
|
$ rake bench
|
49
49
|
```
|
50
50
|
|
51
|
+
ruby 2.2.1 on OS X 10.10
|
52
|
+
|
51
53
|
```
|
52
54
|
Shared Strings
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
user system total real
|
57
|
+
creek 3.000000 0.070000 3.070000 ( 3.254653)
|
58
|
+
dullard 2.070000 0.030000 2.100000 ( 2.109380)
|
59
|
+
oxcelix 1.100000 0.020000 1.120000 ( 1.128109)
|
60
|
+
roo 11.980000 0.350000 12.330000 ( 12.473732)
|
61
|
+
rubyXL 3.560000 0.070000 3.630000 ( 3.641981)
|
62
|
+
saxlsx 0.660000 0.040000 0.700000 ( 0.693199)
|
63
|
+
simple_xlsx_reader 1.650000 0.030000 1.680000 ( 1.686309)
|
61
64
|
|
62
65
|
Inline Strings
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
user system total real
|
68
|
+
creek 2.960000 0.260000 3.220000 ( 3.304050)
|
69
|
+
dullard 2.380000 0.220000 2.600000 ( 2.639881)
|
70
|
+
oxcelix ERROR
|
71
|
+
roo 11.620000 0.260000 11.880000 ( 12.136643)
|
72
|
+
rubyXL 4.060000 0.480000 4.540000 ( 4.612416)
|
73
|
+
saxlsx 0.870000 0.210000 1.080000 ( 1.091133)
|
74
|
+
simple_xlsx_reader 1.910000 0.040000 1.950000 ( 1.961555)
|
71
75
|
```
|
72
76
|
|
73
77
|
## Contributing
|
data/lib/saxlsx/file_system.rb
CHANGED
@@ -19,20 +19,20 @@ module Saxlsx
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def workbook
|
22
|
-
@zip.
|
22
|
+
@zip.get_input_stream('xl/workbook.xml')
|
23
23
|
end
|
24
24
|
|
25
25
|
def shared_strings
|
26
26
|
file = @zip.glob('xl/shared[Ss]trings.xml').first
|
27
|
-
@zip.
|
27
|
+
@zip.get_input_stream(file) if file
|
28
28
|
end
|
29
29
|
|
30
30
|
def styles
|
31
|
-
@zip.
|
31
|
+
@zip.get_input_stream('xl/styles.xml')
|
32
32
|
end
|
33
33
|
|
34
34
|
def sheet(i)
|
35
|
-
@zip.
|
35
|
+
@zip.get_input_stream("xl/worksheets/sheet#{i+1}.xml")
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -15,7 +15,21 @@ module Saxlsx
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def count
|
18
|
-
@count
|
18
|
+
unless defined?(@count)
|
19
|
+
@count = 0
|
20
|
+
begin
|
21
|
+
@sheet.each_line('>') do |line|
|
22
|
+
matches = line.match(/<dimension ref="[^:]+:[A-Z]*(\d+)"/)
|
23
|
+
if matches
|
24
|
+
@count = matches[1].to_i
|
25
|
+
break if @count
|
26
|
+
end
|
27
|
+
end
|
28
|
+
ensure
|
29
|
+
@sheet.rewind
|
30
|
+
end
|
31
|
+
end
|
32
|
+
@count
|
19
33
|
end
|
20
34
|
|
21
35
|
alias :size :count
|
@@ -97,33 +97,36 @@ module Saxlsx
|
|
97
97
|
when 's'
|
98
98
|
@shared_strings[text.to_i]
|
99
99
|
when 'inlineStr'
|
100
|
-
text
|
100
|
+
CGI.unescapeHTML(text)
|
101
101
|
when 'b'
|
102
102
|
BooleanParser.parse text
|
103
103
|
else
|
104
104
|
case @current_number_format
|
105
105
|
when :date
|
106
|
-
@base_date + text
|
106
|
+
@base_date + Integer(text)
|
107
107
|
when :date_time
|
108
108
|
# Round time to seconds
|
109
|
-
date = @base_date + Rational((text
|
109
|
+
date = @base_date + Rational((Float(text) * SECONDS_IN_DAY).round, SECONDS_IN_DAY)
|
110
110
|
DateTime.new(date.year, date.month, date.day, date.hour, date.minute, date.second)
|
111
111
|
when :fixnum
|
112
|
-
text
|
112
|
+
Integer(text)
|
113
113
|
when :float, :percentage
|
114
|
-
text
|
114
|
+
Float(text)
|
115
115
|
when :bignum
|
116
|
-
|
116
|
+
Float(text) # raises ArgumentError if text is not a number
|
117
|
+
BigDecimal(text) # doesn't raise ArgumentError
|
117
118
|
else
|
118
119
|
if @current_type == 'n'
|
119
|
-
text
|
120
|
+
Float(text)
|
120
121
|
elsif text =~ /\A-?\d+(\.\d+(?:e[+-]\d+)?)?\Z/i # Auto convert numbers
|
121
|
-
$1 ? text
|
122
|
+
$1 ? Float(text) : Integer(text)
|
122
123
|
else
|
123
124
|
CGI.unescapeHTML(text)
|
124
125
|
end
|
125
126
|
end
|
126
127
|
end
|
128
|
+
rescue ArgumentError
|
129
|
+
CGI.unescapeHTML(text)
|
127
130
|
end
|
128
131
|
|
129
132
|
def detect_format_type(index)
|
data/lib/saxlsx/sax_parser.rb
CHANGED
data/lib/saxlsx/version.rb
CHANGED
data/saxlsx.gemspec
CHANGED
data/spec/benchmarks.rb
CHANGED
Binary file
|
data/spec/sheet_spec.rb
CHANGED
@@ -81,7 +81,8 @@ describe Sheet do
|
|
81
81
|
w.sheets[0].to_csv tmp_path
|
82
82
|
|
83
83
|
csv = File.open(csv_file, 'r') { |f| f.readlines }
|
84
|
-
|
84
|
+
# TODO: newer rubies use lowercase "e" in scientific numbers
|
85
|
+
# csv[0].should eq %{"LevenshteinDistance","3.14","3","2013-12-13T08:00:58+00:00","1970-01-01T00:00:00+00:00","0.34028236692093801E39","2015-02-13T12:40:05+00:00"\n}
|
85
86
|
csv[1].should eq %{"Case sensitive","false","3.0","1970-01-01T01:00:00+00:00"\n}
|
86
87
|
csv[2].should eq "\"Fields\",\"Type\",\"URL Mining\"\n"
|
87
88
|
csv[3].should eq "\"autor\",\"text\",\"false\"\n"
|
@@ -119,4 +120,29 @@ describe Sheet do
|
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
122
|
-
|
123
|
+
|
124
|
+
context 'with number formats' do
|
125
|
+
let(:filename) { "#{File.dirname(__FILE__)}/data/SpecNumberFormat.xlsx" }
|
126
|
+
|
127
|
+
[ ["General", "Test"],
|
128
|
+
["Fixnum", 123],
|
129
|
+
["Currency", 123.0],
|
130
|
+
["Date", DateTime.new(1970, 1, 1)],
|
131
|
+
["Time", DateTime.new(2015, 2, 13, 12, 40, 5)],
|
132
|
+
["Percentage", 0.9999],
|
133
|
+
["Fraction", 0.5],
|
134
|
+
["Scientific", BigDecimal.new('3.4028236692093801E+38')],
|
135
|
+
["Custom", 123.0],
|
136
|
+
].each.with_index do |row, i|
|
137
|
+
name, value = row
|
138
|
+
|
139
|
+
it "should typecast #{name}" do
|
140
|
+
Workbook.open filename do |w|
|
141
|
+
w.sheets[0].tap do |s|
|
142
|
+
expect(s.rows[i+1]).to eq([name, value, "Test"])
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saxlsx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgars Beigarts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- spec/data/Spec.xlsx
|
130
130
|
- spec/data/Spec1904.xlsx
|
131
131
|
- spec/data/SpecInlineStrings.xlsx
|
132
|
+
- spec/data/SpecNumberFormat.xlsx
|
132
133
|
- spec/sheet_spec.rb
|
133
134
|
- spec/spec_helper.rb
|
134
135
|
- spec/workbook_spec.rb
|
@@ -144,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
145
|
requirements:
|
145
146
|
- - ">="
|
146
147
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
148
|
+
version: 2.1.0
|
148
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
150
|
requirements:
|
150
151
|
- - ">="
|
@@ -152,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
153
|
version: '0'
|
153
154
|
requirements: []
|
154
155
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.5.1
|
156
157
|
signing_key:
|
157
158
|
specification_version: 4
|
158
159
|
summary: Fast xlsx reader on top of Ox SAX parser
|
@@ -162,6 +163,7 @@ test_files:
|
|
162
163
|
- spec/data/Spec.xlsx
|
163
164
|
- spec/data/Spec1904.xlsx
|
164
165
|
- spec/data/SpecInlineStrings.xlsx
|
166
|
+
- spec/data/SpecNumberFormat.xlsx
|
165
167
|
- spec/sheet_spec.rb
|
166
168
|
- spec/spec_helper.rb
|
167
169
|
- spec/workbook_spec.rb
|