xlsxtream 1.3.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/CHANGELOG.md +6 -0
- data/README.md +33 -6
- data/lib/xlsxtream/errors.rb +1 -0
- data/lib/xlsxtream/io/directory.rb +2 -1
- data/lib/xlsxtream/io/stream.rb +1 -0
- data/lib/xlsxtream/io/zip_tricks.rb +44 -0
- data/lib/xlsxtream/io/zip_tricks_fibers.rb +36 -0
- data/lib/xlsxtream/version.rb +1 -1
- data/lib/xlsxtream/workbook.rb +18 -9
- data/xlsxtream.gemspec +4 -3
- metadata +26 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9291c6ab43b7b9218c0341b2556daabe838f919
|
4
|
+
data.tar.gz: 31aca2466d4cbd18fdc4a3ec9181de16a9488f70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd1d0aab1d0c4117f87ccd9efc432977d4057538ecc4769a339ea46f964020a02b255f971ce8aa1a1c2c4af6d28814a8d740ee1cf0fabcfe76d8c6741312fe19
|
7
|
+
data.tar.gz: 5c373153d1b97ca5db24c7c8cd7be7e79605a4129993f2d8b586b3e8ee1fc9c8ccdd51478886a0ca3bebde688ffc72c20e7b932293ff2e2bc861fbcaf6d9cea5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.0.0 (2017-10-31)
|
4
|
+
|
5
|
+
- Replace RubyZip with ZipTricks as default compressor (#16)
|
6
|
+
- Drop support for Ruby < 2.1.0 (required for zip\_tricks gem)
|
7
|
+
- Deprecate :io\_wrapper option, you can now pass wrapper instances (#20)
|
8
|
+
|
3
9
|
## 1.3.2 (2017-10-30)
|
4
10
|
|
5
11
|
- Fix circular require in workbook
|
data/README.md
CHANGED
@@ -61,7 +61,7 @@ end
|
|
61
61
|
# for the workbook or a single worksheet. The SST has to be kept in memory,
|
62
62
|
# so do not use it if you have a huge amount of rows or a little duplication
|
63
63
|
# of content across cells. A single SST is used for the whole workbook.
|
64
|
-
xlsx.write_worksheet('SheetWithSST', :
|
64
|
+
xlsx.write_worksheet('SheetWithSST', use_shared_strings: true) do |sheet|
|
65
65
|
sheet << ['the', 'same', 'old', 'story']
|
66
66
|
sheet << ['the', 'old', 'same', 'story']
|
67
67
|
sheet << ['old', 'the', 'same', 'story']
|
@@ -72,7 +72,7 @@ end
|
|
72
72
|
# "Number stored as text". Dates and times must be in the ISO-8601 format and
|
73
73
|
# numeric values must contain only numbers and an optional decimal separator.
|
74
74
|
# The strings true and false are detected as boolean values.
|
75
|
-
xlsx.write_worksheet('SheetWithAutoFormat', :
|
75
|
+
xlsx.write_worksheet('SheetWithAutoFormat', auto_format: true) do |sheet|
|
76
76
|
# these two rows will be identical in the xlsx-output
|
77
77
|
sheet << [true, 11.85, DateTime.parse('2050-01-01T12:00'), Date.parse('1984-01-01')]
|
78
78
|
sheet << ['true', '11.85', '2050-01-01T12:00', '1984-01-01']
|
@@ -84,14 +84,41 @@ xlsx.close
|
|
84
84
|
io.close
|
85
85
|
|
86
86
|
# Changing the default font from Calibri, 12pt, Swiss
|
87
|
-
Xlsxtream::Workbook.new(io, :
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
87
|
+
Xlsxtream::Workbook.new(io, font: {
|
88
|
+
name: 'Times New Roman',
|
89
|
+
size: 10, # size in pt
|
90
|
+
family: 'Roman' # Swiss, Modern, Script, Decorative
|
91
91
|
})
|
92
92
|
|
93
93
|
```
|
94
94
|
|
95
|
+
## Compatibility
|
96
|
+
|
97
|
+
The current version of Xlsxtream requires at least Ruby 2.1.0.
|
98
|
+
|
99
|
+
If you are using an older Ruby version you can use the following in your Gemfile:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
gem 'xlsxtream', '< 2'
|
103
|
+
```
|
104
|
+
|
105
|
+
* The last version with support for Ruby 1.9.1 is 1.2.0.
|
106
|
+
* The last version with support for Ruby 1.9.2 is 1.3.2.
|
107
|
+
|
108
|
+
## Upgrading
|
109
|
+
|
110
|
+
If you are upgrading from a version earlier than 2.x and are using the undocumented `:io_wrapper` option you need to update your code:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
# Pre 2.x code with :io_wrapper option
|
114
|
+
Xlsxtream::Workbook.new(io, io_wrapper: MyCustomIOWrapper)
|
115
|
+
# New code with IO wrapper instance
|
116
|
+
io_wrapper = MyCustomIOWrapper.new(io)
|
117
|
+
Xlsxtream::Workbook.new(io_wrapper)
|
118
|
+
```
|
119
|
+
|
120
|
+
Every IO-like object that responds to `:add_file` is treated as an IO wrapper.
|
121
|
+
|
95
122
|
## Development
|
96
123
|
|
97
124
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/xlsxtream/errors.rb
CHANGED
@@ -5,6 +5,7 @@ module Xlsxtream
|
|
5
5
|
class Directory
|
6
6
|
def initialize(path)
|
7
7
|
@path = Pathname(path)
|
8
|
+
@file = nil
|
8
9
|
end
|
9
10
|
|
10
11
|
def <<(data)
|
@@ -19,7 +20,7 @@ module Xlsxtream
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def close
|
22
|
-
@file.close if @file
|
23
|
+
@file.close if @file
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/lib/xlsxtream/io/stream.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "zip_tricks"
|
2
|
+
|
3
|
+
module Xlsxtream
|
4
|
+
module IO
|
5
|
+
class ZipTricks
|
6
|
+
BUFFER_SIZE = 64 * 1024
|
7
|
+
|
8
|
+
def initialize(body)
|
9
|
+
@streamer = ::ZipTricks::Streamer.new(body)
|
10
|
+
@wf = nil
|
11
|
+
@buffer = ''
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(data)
|
15
|
+
@buffer << data
|
16
|
+
flush_buffer if @buffer.size >= BUFFER_SIZE
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_file(path)
|
21
|
+
flush_file
|
22
|
+
@wf = @streamer.write_deflated_file(path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def close
|
26
|
+
flush_file
|
27
|
+
@streamer.close
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def flush_buffer
|
33
|
+
@wf << @buffer
|
34
|
+
@buffer.clear
|
35
|
+
end
|
36
|
+
|
37
|
+
def flush_file
|
38
|
+
return unless @wf
|
39
|
+
flush_buffer if @buffer.size > 0
|
40
|
+
@wf.close
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "zip_tricks"
|
2
|
+
|
3
|
+
module Xlsxtream
|
4
|
+
module IO
|
5
|
+
class ZipTricksFibers
|
6
|
+
def initialize(body)
|
7
|
+
@streamer = ::ZipTricks::Streamer.new(body)
|
8
|
+
@wf = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(data)
|
12
|
+
@wf.resume(data)
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_file(path)
|
17
|
+
@wf.resume(:__close__) if @wf
|
18
|
+
|
19
|
+
@wf = Fiber.new do | bytes_or_close_sym |
|
20
|
+
@streamer.write_deflated_file(path) do |write_sink|
|
21
|
+
loop do
|
22
|
+
break if bytes_or_close_sym == :__close__
|
23
|
+
write_sink << bytes_or_close_sym
|
24
|
+
bytes_or_close_sym = Fiber.yield
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def close
|
31
|
+
@wf.resume(:__close__) if @wf
|
32
|
+
@streamer.close
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/xlsxtream/version.rb
CHANGED
data/lib/xlsxtream/workbook.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require "stringio"
|
3
2
|
require "xlsxtream/errors"
|
4
3
|
require "xlsxtream/xml"
|
5
4
|
require "xlsxtream/shared_string_table"
|
6
5
|
require "xlsxtream/worksheet"
|
7
|
-
require "xlsxtream/io/
|
6
|
+
require "xlsxtream/io/zip_tricks"
|
8
7
|
|
9
8
|
module Xlsxtream
|
10
9
|
class Workbook
|
@@ -20,7 +19,7 @@ module Xlsxtream
|
|
20
19
|
|
21
20
|
class << self
|
22
21
|
|
23
|
-
def open(output
|
22
|
+
def open(output, options = {})
|
24
23
|
workbook = new(output, options)
|
25
24
|
if block_given?
|
26
25
|
begin
|
@@ -35,15 +34,25 @@ module Xlsxtream
|
|
35
34
|
|
36
35
|
end
|
37
36
|
|
38
|
-
def initialize(output
|
39
|
-
output
|
37
|
+
def initialize(output, options = {})
|
38
|
+
if output.nil?
|
39
|
+
fail Error, "Xlsxtream::Workbook.new output cannot be nil"
|
40
|
+
end
|
40
41
|
@options = options
|
41
|
-
|
42
|
+
if options[:io_wrapper]
|
43
|
+
fail Deprecation,
|
44
|
+
"The Xlsxtream::Workbook.new :io_wrapper option is deprecated. "\
|
45
|
+
"Please pass an IO wrapper instance as the first argument instead."
|
46
|
+
end
|
42
47
|
if output.is_a?(String) || !output.respond_to?(:<<)
|
43
48
|
@file = File.open(output, 'wb')
|
44
|
-
@io =
|
49
|
+
@io = IO::ZipTricks.new(@file)
|
50
|
+
elsif output.respond_to? :add_file
|
51
|
+
@file = nil
|
52
|
+
@io = output
|
45
53
|
else
|
46
|
-
@
|
54
|
+
@file = nil
|
55
|
+
@io = IO::ZipTricks.new(output)
|
47
56
|
end
|
48
57
|
@sst = SharedStringTable.new
|
49
58
|
@worksheets = Hash.new { |hash, name| hash[name] = hash.size + 1 }
|
@@ -77,7 +86,7 @@ module Xlsxtream
|
|
77
86
|
write_workbook_rels
|
78
87
|
write_root_rels
|
79
88
|
write_content_types
|
80
|
-
@io.close
|
89
|
+
@io.close if @io.respond_to? :close
|
81
90
|
@file.close if @file
|
82
91
|
nil
|
83
92
|
end
|
data/xlsxtream.gemspec
CHANGED
@@ -18,12 +18,13 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.bindir = "exe"
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
|
-
spec.required_ruby_version =
|
21
|
+
spec.required_ruby_version = ">= 2.1.0"
|
22
22
|
|
23
|
-
spec.add_dependency "
|
23
|
+
spec.add_dependency "zip_tricks", "~> 4.5"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
-
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rubyzip", "~> 1.2"
|
27
28
|
spec.add_development_dependency "minitest"
|
28
29
|
spec.add_development_dependency "pry"
|
29
30
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlsxtream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Bünemann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: zip_tricks
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '4.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '4.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,18 +40,32 @@ dependencies:
|
|
40
40
|
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubyzip
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '1.2'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '1.2'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: minitest
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +117,8 @@ files:
|
|
103
117
|
- lib/xlsxtream/io/hash.rb
|
104
118
|
- lib/xlsxtream/io/rubyzip.rb
|
105
119
|
- lib/xlsxtream/io/stream.rb
|
120
|
+
- lib/xlsxtream/io/zip_tricks.rb
|
121
|
+
- lib/xlsxtream/io/zip_tricks_fibers.rb
|
106
122
|
- lib/xlsxtream/row.rb
|
107
123
|
- lib/xlsxtream/shared_string_table.rb
|
108
124
|
- lib/xlsxtream/version.rb
|
@@ -122,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
138
|
requirements:
|
123
139
|
- - ">="
|
124
140
|
- !ruby/object:Gem::Version
|
125
|
-
version: 1.
|
141
|
+
version: 2.1.0
|
126
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
143
|
requirements:
|
128
144
|
- - ">="
|