xlsxtream 2.3.0 → 2.4.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 +6 -4
- data/CHANGELOG.md +6 -0
- data/README.md +7 -0
- data/lib/xlsxtream/version.rb +1 -1
- data/lib/xlsxtream/workbook.rb +43 -20
- data/lib/xlsxtream/worksheet.rb +14 -0
- data/xlsxtream.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad3cd850f298db3909ce061876610fdaad2de689675d9b23d6738f8a177f5254
|
4
|
+
data.tar.gz: 5b1002fa1031cd53612735d6732acd43a8b0c086aaccc0f62f9a761583f21c5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bed396c449a050615e3822fc9c76935db6e9c7cb7434bc5a49c4effd76221ed66a023be3cff3859f30d290259c33cf685f8e8a2baaa237d52ae5787b79ee7d67
|
7
|
+
data.tar.gz: 5c31396c6b49b90c7eb9f4fd4a32959ff97eefbe2fa0936833dfc4326954d6e06a267ee4e97ee42faaf8268a2147b3e15edc1ed3341f55794e96f5531afff601
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.4.0 (2020-06-27)
|
4
|
+
|
5
|
+
- Allow writing worksheets without a block using add\_worksheet (#42, #45)
|
6
|
+
- Deprecate calling add\_worksheet with a block, use write\_worksheet instead (#45)
|
7
|
+
- Relax rubyzip development dependency to allow current version (#46)
|
8
|
+
|
3
9
|
## 2.3.0 (2019-11-27)
|
4
10
|
|
5
11
|
- Speed up date / time conversion to OA format (#39)
|
data/README.md
CHANGED
@@ -78,6 +78,13 @@ xlsx.write_worksheet(name: 'SheetWithAutoFormat', auto_format: true) do |sheet|
|
|
78
78
|
sheet << ['true', '11.85', '2050-01-01T12:00', '1984-01-01']
|
79
79
|
end
|
80
80
|
|
81
|
+
# You can also create worksheet without a block, using the `add_worksheet` method.
|
82
|
+
# It can be only used sequentially, so remember to manually close the worksheet
|
83
|
+
# when you are done (before opening a new one).
|
84
|
+
worksheet = xls.add_worksheet(name: 'SheetWithoutBlock')
|
85
|
+
worksheet << ['some', 'data']
|
86
|
+
worksheet.close
|
87
|
+
|
81
88
|
# Writes metadata and ZIP archive central directory
|
82
89
|
xlsx.close
|
83
90
|
# Close IO object
|
data/lib/xlsxtream/version.rb
CHANGED
data/lib/xlsxtream/workbook.rb
CHANGED
@@ -55,30 +55,32 @@ module Xlsxtream
|
|
55
55
|
@io = IO::ZipTricks.new(output)
|
56
56
|
end
|
57
57
|
@sst = SharedStringTable.new
|
58
|
-
@worksheets =
|
58
|
+
@worksheets = []
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
62
|
-
if
|
63
|
-
|
64
|
-
|
61
|
+
def add_worksheet(*args, &block)
|
62
|
+
if block_given?
|
63
|
+
# This method used to be an alias for `write_worksheet`. This was never publicly documented,
|
64
|
+
# but to avoid breaking this private API we keep the old behaviour when called with a block.
|
65
|
+
Kernel.warn "#{caller.first[/.*:\d+:(?=in `)/]} warning: Calling #{self.class}#add_worksheet with a block is deprecated, use #write_worksheet instead."
|
66
|
+
return write_worksheet(*args, &block)
|
65
67
|
end
|
66
|
-
use_sst = options.fetch(:use_shared_strings, @options[:use_shared_strings])
|
67
|
-
auto_format = options.fetch(:auto_format, @options[:auto_format])
|
68
|
-
columns = options.fetch(:columns, @options[:columns])
|
69
|
-
sst = use_sst ? @sst : nil
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
unless @worksheets.all? { |ws| ws.closed? }
|
70
|
+
fail Error, "Close the current worksheet before adding a new one"
|
71
|
+
end
|
72
|
+
|
73
|
+
build_worksheet(*args)
|
74
|
+
end
|
75
|
+
|
76
|
+
def write_worksheet(*args)
|
77
|
+
worksheet = build_worksheet(*args)
|
74
78
|
|
75
|
-
worksheet = Worksheet.new(@io, :sst => sst, :auto_format => auto_format, :columns => columns)
|
76
79
|
yield worksheet if block_given?
|
77
80
|
worksheet.close
|
78
81
|
|
79
82
|
nil
|
80
83
|
end
|
81
|
-
alias_method :add_worksheet, :write_worksheet
|
82
84
|
|
83
85
|
def close
|
84
86
|
write_workbook
|
@@ -93,6 +95,27 @@ module Xlsxtream
|
|
93
95
|
end
|
94
96
|
|
95
97
|
private
|
98
|
+
def build_worksheet(name = nil, options = {})
|
99
|
+
if name.is_a? Hash and options.empty?
|
100
|
+
options = name
|
101
|
+
name = nil
|
102
|
+
end
|
103
|
+
|
104
|
+
use_sst = options.fetch(:use_shared_strings, @options[:use_shared_strings])
|
105
|
+
auto_format = options.fetch(:auto_format, @options[:auto_format])
|
106
|
+
columns = options.fetch(:columns, @options[:columns])
|
107
|
+
sst = use_sst ? @sst : nil
|
108
|
+
|
109
|
+
sheet_id = @worksheets.size + 1
|
110
|
+
name = name || options[:name] || "Sheet#{sheet_id}"
|
111
|
+
|
112
|
+
@io.add_file "xl/worksheets/sheet#{sheet_id}.xml"
|
113
|
+
|
114
|
+
worksheet = Worksheet.new(@io, :id => sheet_id, :name => name, :sst => sst, :auto_format => auto_format, :columns => columns)
|
115
|
+
@worksheets << worksheet
|
116
|
+
|
117
|
+
worksheet
|
118
|
+
end
|
96
119
|
|
97
120
|
def write_root_rels
|
98
121
|
@io.add_file "_rels/.rels"
|
@@ -113,8 +136,8 @@ module Xlsxtream
|
|
113
136
|
<workbookPr date1904="false"/>
|
114
137
|
<sheets>
|
115
138
|
XML
|
116
|
-
@worksheets.each do |
|
117
|
-
@io << %'<sheet name="#{XML.escape_attr name}" sheetId="#{
|
139
|
+
@worksheets.each do |worksheet|
|
140
|
+
@io << %'<sheet name="#{XML.escape_attr worksheet.name}" sheetId="#{worksheet.id}" r:id="#{rid.next!}"/>'
|
118
141
|
end
|
119
142
|
@io << XML.strip(<<-XML)
|
120
143
|
</sheets>
|
@@ -189,8 +212,8 @@ module Xlsxtream
|
|
189
212
|
@io.add_file "xl/_rels/workbook.xml.rels"
|
190
213
|
@io << XML.header
|
191
214
|
@io << '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
|
192
|
-
@worksheets.each do |
|
193
|
-
@io << %'<Relationship Id="#{rid.next!}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet#{
|
215
|
+
@worksheets.each do |worksheet|
|
216
|
+
@io << %'<Relationship Id="#{rid.next!}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet#{worksheet.id}.xml"/>'
|
194
217
|
end
|
195
218
|
@io << %'<Relationship Id="#{rid.next!}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>'
|
196
219
|
@io << %'<Relationship Id="#{rid.next!}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>' unless @sst.empty?
|
@@ -208,8 +231,8 @@ module Xlsxtream
|
|
208
231
|
<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>
|
209
232
|
XML
|
210
233
|
@io << '<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>' unless @sst.empty?
|
211
|
-
@worksheets.
|
212
|
-
@io << %'<Override PartName="/xl/worksheets/sheet#{
|
234
|
+
@worksheets.each do |worksheet|
|
235
|
+
@io << %'<Override PartName="/xl/worksheets/sheet#{worksheet.id}.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>'
|
213
236
|
end
|
214
237
|
@io << '</Types>'
|
215
238
|
end
|
data/lib/xlsxtream/worksheet.rb
CHANGED
@@ -7,6 +7,7 @@ module Xlsxtream
|
|
7
7
|
def initialize(io, options = {})
|
8
8
|
@io = io
|
9
9
|
@rownum = 1
|
10
|
+
@closed = false
|
10
11
|
@options = options
|
11
12
|
|
12
13
|
write_header
|
@@ -20,6 +21,19 @@ module Xlsxtream
|
|
20
21
|
|
21
22
|
def close
|
22
23
|
write_footer
|
24
|
+
@closed = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def closed?
|
28
|
+
@closed
|
29
|
+
end
|
30
|
+
|
31
|
+
def id
|
32
|
+
@options[:id]
|
33
|
+
end
|
34
|
+
|
35
|
+
def name
|
36
|
+
@options[:name]
|
23
37
|
end
|
24
38
|
|
25
39
|
private
|
data/xlsxtream.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", ">= 1.7", "< 3"
|
26
26
|
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rubyzip", "
|
27
|
+
spec.add_development_dependency "rubyzip", ">= 1.2"
|
28
28
|
spec.add_development_dependency "minitest"
|
29
29
|
spec.add_development_dependency "pry"
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlsxtream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Bünemann
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip_tricks
|
@@ -68,14 +68,14 @@ dependencies:
|
|
68
68
|
name: rubyzip
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '1.2'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '1.2'
|
81
81
|
- !ruby/object:Gem::Dependency
|
@@ -142,7 +142,7 @@ homepage: https://github.com/felixbuenemann/xlsxtream
|
|
142
142
|
licenses:
|
143
143
|
- MIT
|
144
144
|
metadata: {}
|
145
|
-
post_install_message:
|
145
|
+
post_install_message:
|
146
146
|
rdoc_options: []
|
147
147
|
require_paths:
|
148
148
|
- lib
|
@@ -157,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
161
|
-
signing_key:
|
160
|
+
rubygems_version: 3.1.2
|
161
|
+
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: Xlsxtream is a streaming XLSX spreadsheet writer
|
164
164
|
test_files: []
|