saxlsx 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +24 -8
- data/Rakefile +3 -65
- data/lib/saxlsx/file_system.rb +1 -2
- data/lib/saxlsx/version.rb +1 -1
- data/spec/benchmarks.rb +143 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8846f61615fb9bef698366383838cca50957a242
|
4
|
+
data.tar.gz: 5fd15e93f3cac8c82eb292abe9202eeea69259d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2450c4efabb247287a16e9daf331f6be1c6ddc8c3f3abdd47b556c8e09e6234a86fb1bbad533fa0a7f18631cdd8dd7207931d78e127eb30045b5a2b95b37844c
|
7
|
+
data.tar.gz: d272886859b32e9e851a52163d8c86f4fcfa5b5f5395e42687eebaaa61525f1672357f009a15bca982c9b8d89df75028aa358a32d9691189db1c32e31f9c72c8
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Saxlsx
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Join the chat at https://gitter.im/mak-it/saxlsx](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mak-it/saxlsx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/mak-it/saxlsx.svg?branch=master)](https://travis-ci.org/mak-it/saxlsx)
|
4
6
|
|
5
7
|
**Fast** and memory efficient XLSX reader on top of Ox SAX parser.
|
6
8
|
|
7
9
|
It reads row by row and doesn't store the whole sheet in memory, so this
|
8
|
-
approach is more suitable when parsing big files.
|
9
|
-
and references will not work, as this style of parsing doesn't know
|
10
|
-
anything about other rows.
|
10
|
+
approach is more suitable when parsing big files.
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -34,6 +34,7 @@ $ gem install saxlsx
|
|
34
34
|
```ruby
|
35
35
|
Saxlsx::Workbook.open filename do |w|
|
36
36
|
w.sheets.each do |s|
|
37
|
+
puts s.rows.count
|
37
38
|
s.rows.each do |r|
|
38
39
|
puts r.inspect
|
39
40
|
end
|
@@ -48,10 +49,25 @@ $ rake bench
|
|
48
49
|
```
|
49
50
|
|
50
51
|
```
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
Shared Strings
|
53
|
+
|
54
|
+
creek 3.200000 0.060000 3.260000 ( 3.392446)
|
55
|
+
dullard 3.020000 0.070000 3.090000 ( 3.154582)
|
56
|
+
oxcelix 1.720000 0.060000 1.780000 ( 1.824003)
|
57
|
+
roo 14.580000 0.490000 15.070000 ( 15.311664)
|
58
|
+
rubyXL 5.180000 0.160000 5.340000 ( 5.432973)
|
59
|
+
saxlsx 1.020000 0.010000 1.030000 ( 1.044249)
|
60
|
+
simple_xlsx_reader 2.580000 0.050000 2.630000 ( 2.660065)
|
61
|
+
|
62
|
+
Inline Strings
|
63
|
+
|
64
|
+
creek 3.970000 0.330000 4.300000 ( 4.395139)
|
65
|
+
dullard 3.700000 0.360000 4.060000 ( 4.174130)
|
66
|
+
oxcelix ERROR
|
67
|
+
roo 14.700000 0.550000 15.250000 ( 15.644152)
|
68
|
+
rubyXL 5.830000 0.440000 6.270000 ( 6.365362)
|
69
|
+
saxlsx 1.500000 0.040000 1.540000 ( 1.679372)
|
70
|
+
simple_xlsx_reader 2.790000 0.070000 2.860000 ( 2.916020)
|
55
71
|
```
|
56
72
|
|
57
73
|
## Contributing
|
data/Rakefile
CHANGED
@@ -7,68 +7,6 @@ task :default => :spec
|
|
7
7
|
|
8
8
|
|
9
9
|
task :bench do
|
10
|
-
require '
|
11
|
-
|
12
|
-
|
13
|
-
require 'rubyXL'
|
14
|
-
require 'simple_xlsx_reader'
|
15
|
-
require 'creek'
|
16
|
-
|
17
|
-
path = "tmp/bench.xlsx"
|
18
|
-
unless File.exists?(path)
|
19
|
-
puts "* Generating #{path}"
|
20
|
-
FileUtils.mkdir_p File.dirname(path)
|
21
|
-
Axlsx::Package.new do |p|
|
22
|
-
money_style = p.workbook.styles.add_style(
|
23
|
-
num_fmt: 5, format_code: "€0.000"
|
24
|
-
)
|
25
|
-
p.workbook.add_worksheet(:name => "Pie Chart") do |sheet|
|
26
|
-
10000.times do
|
27
|
-
sheet.add_row(
|
28
|
-
[Date.today, Time.now, 1000, 3.14, "Long" * 100],
|
29
|
-
types: [:date, :time, :integer, :float, :string],
|
30
|
-
style: [nil, nil, nil, money_style, nil]
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
p.use_shared_strings = true
|
35
|
-
p.serialize(path)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
Benchmark.benchmark('', 20) do |x|
|
40
|
-
x.report "creek" do
|
41
|
-
w = Creek::Book.new path
|
42
|
-
w.sheets.each do |s|
|
43
|
-
s.rows.each do |r|
|
44
|
-
r.values.inspect
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
x.report "rubyXL" do
|
49
|
-
w = RubyXL::Parser.parse path
|
50
|
-
w.worksheets.each do |s|
|
51
|
-
s.each do |r|
|
52
|
-
r.cells.map(&:value).inspect
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
x.report "saxlsx" do
|
57
|
-
Saxlsx::Workbook.open path do |w|
|
58
|
-
w.sheets.each do |s|
|
59
|
-
s.rows.each do |r|
|
60
|
-
r.to_a.inspect
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
x.report "simple_xlsx_reader" do
|
66
|
-
w = SimpleXlsxReader.open path
|
67
|
-
w.sheets.each do |s|
|
68
|
-
s.rows.each do |r|
|
69
|
-
r.to_a.inspect
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
10
|
+
require './spec/benchmarks.rb'
|
11
|
+
Saxlsx::Benchmarks.new.run
|
12
|
+
end
|
data/lib/saxlsx/file_system.rb
CHANGED
data/lib/saxlsx/version.rb
CHANGED
data/spec/benchmarks.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'axlsx'
|
3
|
+
require 'saxlsx'
|
4
|
+
require 'rubyXL'
|
5
|
+
require 'simple_xlsx_reader'
|
6
|
+
require 'creek'
|
7
|
+
require 'oxcelix'
|
8
|
+
require 'roo'
|
9
|
+
require 'dullard'
|
10
|
+
|
11
|
+
module Saxlsx
|
12
|
+
class Benchmarks
|
13
|
+
def run
|
14
|
+
path = "tmp/bench_shared_strings.xlsx"
|
15
|
+
generate path, true
|
16
|
+
benchmark "Shared Strings", path
|
17
|
+
|
18
|
+
path = "tmp/bench_inline_strings.xlsx"
|
19
|
+
generate path, false
|
20
|
+
benchmark "Inline Strings", path
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def generate(path, shared_strings)
|
26
|
+
unless File.exists?(path)
|
27
|
+
puts "* Generating #{path}"
|
28
|
+
FileUtils.mkdir_p File.dirname(path)
|
29
|
+
Axlsx::Package.new do |p|
|
30
|
+
money_style = p.workbook.styles.add_style(
|
31
|
+
num_fmt: 5, format_code: "€0.000"
|
32
|
+
)
|
33
|
+
p.workbook.add_worksheet(:name => "Sheet 1") do |sheet|
|
34
|
+
10000.times do
|
35
|
+
sheet.add_row(
|
36
|
+
[Date.today, Time.now, 1000, 3.14, "Long" * 100],
|
37
|
+
types: [:date, :time, :integer, :float, :string],
|
38
|
+
style: [nil, nil, nil, money_style, nil]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
p.use_shared_strings = shared_strings
|
43
|
+
p.serialize(path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def benchmark(title, path)
|
49
|
+
puts
|
50
|
+
puts title
|
51
|
+
puts
|
52
|
+
Benchmark.benchmark('', 20) do |x|
|
53
|
+
x.report "creek" do
|
54
|
+
run_creek(path)
|
55
|
+
end
|
56
|
+
x.report "dullard" do
|
57
|
+
run_dullard(path)
|
58
|
+
end
|
59
|
+
x.report "oxcelix" do
|
60
|
+
run_oxcelix(path)
|
61
|
+
end
|
62
|
+
x.report "roo" do
|
63
|
+
run_roo(path)
|
64
|
+
end
|
65
|
+
x.report "rubyXL" do
|
66
|
+
run_rubyxl(path)
|
67
|
+
end
|
68
|
+
x.report "saxlsx" do
|
69
|
+
run_saxlsx(path)
|
70
|
+
end
|
71
|
+
x.report "simple_xlsx_reader" do
|
72
|
+
run_simple_xlsx_reader(path)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def run_creek(path)
|
78
|
+
w = Creek::Book.new path
|
79
|
+
w.sheets.each do |s|
|
80
|
+
s.rows.each do |r|
|
81
|
+
r.values.inspect
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def run_oxcelix(path)
|
87
|
+
w = Oxcelix::Workbook.new(path)
|
88
|
+
w.sheets.each do |s|
|
89
|
+
s.to_ru.to_a.each do |r|
|
90
|
+
r.inspect
|
91
|
+
end
|
92
|
+
end
|
93
|
+
rescue
|
94
|
+
puts "ERROR"
|
95
|
+
end
|
96
|
+
|
97
|
+
def run_rubyxl(path)
|
98
|
+
w = RubyXL::Parser.parse path
|
99
|
+
w.worksheets.each do |s|
|
100
|
+
s.each do |r|
|
101
|
+
r.cells.map(&:value).inspect
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def run_saxlsx(path)
|
107
|
+
Saxlsx::Workbook.open path do |w|
|
108
|
+
w.sheets.each do |s|
|
109
|
+
s.rows.each do |r|
|
110
|
+
r.to_a.inspect
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def run_simple_xlsx_reader(path)
|
117
|
+
w = SimpleXlsxReader.open path
|
118
|
+
w.sheets.each do |s|
|
119
|
+
s.rows.each do |r|
|
120
|
+
r.to_a.inspect
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def run_roo(path)
|
126
|
+
w = Roo::Excelx.new path
|
127
|
+
w.each_with_pagename do |_, s|
|
128
|
+
s.each do |r|
|
129
|
+
r.to_a.inspect
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def run_dullard(path)
|
135
|
+
w = Dullard::Workbook.new path
|
136
|
+
w.sheets.each do |s|
|
137
|
+
s.rows.each do |r|
|
138
|
+
r.to_a.inspect
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saxlsx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgars Beigarts
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/saxlsx/version.rb
|
125
125
|
- lib/saxlsx/workbook.rb
|
126
126
|
- saxlsx.gemspec
|
127
|
+
- spec/benchmarks.rb
|
127
128
|
- spec/column_name_generator_spec.rb
|
128
129
|
- spec/data/Spec.xlsx
|
129
130
|
- spec/data/Spec1904.xlsx
|
@@ -156,6 +157,7 @@ signing_key:
|
|
156
157
|
specification_version: 4
|
157
158
|
summary: Fast xlsx reader on top of Ox SAX parser
|
158
159
|
test_files:
|
160
|
+
- spec/benchmarks.rb
|
159
161
|
- spec/column_name_generator_spec.rb
|
160
162
|
- spec/data/Spec.xlsx
|
161
163
|
- spec/data/Spec1904.xlsx
|