xlsxtream 2.0.1 → 2.1.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 +4 -3
- data/CHANGELOG.md +7 -1
- data/README.md +14 -2
- data/lib/xlsxtream.rb +2 -0
- data/lib/xlsxtream/columns.rb +57 -0
- data/lib/xlsxtream/errors.rb +1 -0
- data/lib/xlsxtream/io/directory.rb +1 -0
- data/lib/xlsxtream/io/hash.rb +1 -0
- data/lib/xlsxtream/io/rubyzip.rb +1 -0
- data/lib/xlsxtream/io/stream.rb +1 -0
- data/lib/xlsxtream/io/zip_tricks.rb +2 -1
- data/lib/xlsxtream/row.rb +3 -3
- data/lib/xlsxtream/shared_string_table.rb +1 -0
- data/lib/xlsxtream/version.rb +2 -1
- data/lib/xlsxtream/workbook.rb +6 -5
- data/lib/xlsxtream/worksheet.rb +9 -1
- data/lib/xlsxtream/xml.rb +1 -0
- data/xlsxtream.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8cc8d872dffb10c74eca0a31318350d2343ee609475a67a1aedc4c515ecc786
|
|
4
|
+
data.tar.gz: 715eae8f94c4a59f86b4abb1ec263266a481383fee3ceee912804f96cc6c592a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4c2025bc90c39d416af05af138c91439d4c0a16e9f20c0be718505c8809013044f060938284006d536be11862974f2041c983da0885f788fd02c09355df6c80
|
|
7
|
+
data.tar.gz: 70e5a60021a8c64a7adda9a3bcbac071a73f2fce8cc62c709ab502c34693e5c931532c5215023a10c627b31b1b68eeff9bc26f7b90e5d386455ab70f20aa581b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.1.0 (2018-07-21)
|
|
4
|
+
|
|
5
|
+
- New `:columns` option, allowing column widths to be specified (#25)
|
|
6
|
+
- Fix compatibility with `ruby --enable-frozen-string-literal` (#27)
|
|
7
|
+
- Support giving the worksheet name as an option to write\_worksheet (#28)
|
|
8
|
+
|
|
3
9
|
## 2.0.1 (2018-03-11)
|
|
4
10
|
|
|
5
11
|
- Rescue gracefully from invalid dates with auto-format (#22)
|
|
@@ -48,7 +54,7 @@
|
|
|
48
54
|
|
|
49
55
|
## 0.3.0 (2017-07-12)
|
|
50
56
|
|
|
51
|
-
- Add support for auto-formatting
|
|
57
|
+
- Add support for auto-formatting (#8)
|
|
52
58
|
|
|
53
59
|
## 0.2.0 (2017-02-20)
|
|
54
60
|
|
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', use_shared_strings: true) do |sheet|
|
|
64
|
+
xlsx.write_worksheet(name: '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', auto_format: true) do |sheet|
|
|
75
|
+
xlsx.write_worksheet(name: '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']
|
|
@@ -90,8 +90,20 @@ Xlsxtream::Workbook.new(io, font: {
|
|
|
90
90
|
family: 'Roman' # Swiss, Modern, Script, Decorative
|
|
91
91
|
})
|
|
92
92
|
|
|
93
|
+
# Specifying column widths in pixels or characters; 3 column example;
|
|
94
|
+
# "pixel" widths appear to be *relative* to an assumed 11pt Calibri
|
|
95
|
+
# font, so if selecting a different font or size (see above), do not
|
|
96
|
+
# adjust widths to match. Calculate pixel widths for 11pt Calibri.
|
|
97
|
+
Xlsxtream::Workbook.new(io, columns: [
|
|
98
|
+
{ width_pixels: 33 },
|
|
99
|
+
{ width_chars: 7 },
|
|
100
|
+
{ width_chars: 24 }
|
|
101
|
+
])
|
|
102
|
+
# The :columns option can also be given to write_worksheet, so it's
|
|
103
|
+
# possible to have multiple worksheets with different column widths.
|
|
93
104
|
```
|
|
94
105
|
|
|
106
|
+
|
|
95
107
|
## Compatibility
|
|
96
108
|
|
|
97
109
|
The current version of Xlsxtream requires at least Ruby 2.1.0.
|
data/lib/xlsxtream.rb
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Xlsxtream
|
|
3
|
+
class Columns
|
|
4
|
+
|
|
5
|
+
# Pass an Array of column options Hashes. Symbol Hash keys and associated
|
|
6
|
+
# values are as follows:
|
|
7
|
+
#
|
|
8
|
+
# +width_chars+:: Approximate column with in characters, calculated per
|
|
9
|
+
# MSDN docs as if using a default 11 point Calibri font
|
|
10
|
+
# for a 96 DPI target. Specify as an integer.
|
|
11
|
+
#
|
|
12
|
+
# +width_pixels+:: Exact with of column in pixels. Specify as a Float.
|
|
13
|
+
# Overrides +width_chars+ if that is also provided.
|
|
14
|
+
#
|
|
15
|
+
def initialize(column_options_array)
|
|
16
|
+
@columns = column_options_array
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_xml
|
|
20
|
+
xml = String.new('<cols>')
|
|
21
|
+
|
|
22
|
+
@columns.each_with_index do |column, index|
|
|
23
|
+
width_chars = column[ :width_chars ]
|
|
24
|
+
width_pixels = column[ :width_pixels ]
|
|
25
|
+
|
|
26
|
+
if width_chars.nil? && width_pixels.nil?
|
|
27
|
+
xml << %Q{<col min="#{index + 1}" max="#{index + 1}"/>}
|
|
28
|
+
else
|
|
29
|
+
|
|
30
|
+
# https://msdn.microsoft.com/en-us/library/office/documentformat.openxml.spreadsheet.column.aspx
|
|
31
|
+
#
|
|
32
|
+
# Truncate(
|
|
33
|
+
# [{Number of Characters} * {Maximum Digit Width} + {5 pixel padding}]
|
|
34
|
+
# /{Maximum Digit Width}*256
|
|
35
|
+
# )/256
|
|
36
|
+
#
|
|
37
|
+
# "Using the Calibri font as an example, the maximum digit width of
|
|
38
|
+
# 11 point font size is 7 pixels (at 96 dpi)"
|
|
39
|
+
#
|
|
40
|
+
# By observation, though, I note that a different spreadsheet-wide
|
|
41
|
+
# font size selected via the Workbook's ":font => { :size => ... }"
|
|
42
|
+
# options Hash entry results in Excel, at least, scaling the given
|
|
43
|
+
# widths in proportion with the requested font size change. We do
|
|
44
|
+
# not, apparently, need to do that ourselves and run the calculation
|
|
45
|
+
# based on the reference 11 point -> 7 pixel figure.
|
|
46
|
+
#
|
|
47
|
+
width_pixels ||= ((((width_chars * 7.0) + 5) / 7) * 256).truncate() / 256.0
|
|
48
|
+
|
|
49
|
+
xml << %Q{<col min="#{index + 1}" max="#{index + 1}" width="#{width_pixels}" customWidth="1"/>}
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
xml << '</cols>'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/xlsxtream/errors.rb
CHANGED
data/lib/xlsxtream/io/hash.rb
CHANGED
data/lib/xlsxtream/io/rubyzip.rb
CHANGED
data/lib/xlsxtream/io/stream.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require "zip_tricks"
|
|
2
3
|
|
|
3
4
|
module Xlsxtream
|
|
@@ -8,7 +9,7 @@ module Xlsxtream
|
|
|
8
9
|
def initialize(body)
|
|
9
10
|
@streamer = ::ZipTricks::Streamer.new(body)
|
|
10
11
|
@wf = nil
|
|
11
|
-
@buffer =
|
|
12
|
+
@buffer = String.new
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def <<(data)
|
data/lib/xlsxtream/row.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
require "date"
|
|
3
3
|
require "xlsxtream/xml"
|
|
4
4
|
|
|
@@ -27,8 +27,8 @@ module Xlsxtream
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def to_xml
|
|
30
|
-
column = 'A'
|
|
31
|
-
xml = %Q{<row r="#{@rownum}">}
|
|
30
|
+
column = String.new('A')
|
|
31
|
+
xml = String.new(%Q{<row r="#{@rownum}">})
|
|
32
32
|
|
|
33
33
|
@row.each do |value|
|
|
34
34
|
cid = "#{column}#{@rownum}"
|
data/lib/xlsxtream/version.rb
CHANGED
data/lib/xlsxtream/workbook.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
require "xlsxtream/errors"
|
|
3
3
|
require "xlsxtream/xml"
|
|
4
4
|
require "xlsxtream/shared_string_table"
|
|
@@ -65,13 +65,14 @@ module Xlsxtream
|
|
|
65
65
|
end
|
|
66
66
|
use_sst = options.fetch(:use_shared_strings, @options[:use_shared_strings])
|
|
67
67
|
auto_format = options.fetch(:auto_format, @options[:auto_format])
|
|
68
|
+
columns = options.fetch(:columns, @options[:columns])
|
|
68
69
|
sst = use_sst ? @sst : nil
|
|
69
70
|
|
|
70
|
-
name
|
|
71
|
+
name = name || options[:name] || "Sheet#{@worksheets.size + 1}"
|
|
71
72
|
sheet_id = @worksheets[name]
|
|
72
73
|
@io.add_file "xl/worksheets/sheet#{sheet_id}.xml"
|
|
73
74
|
|
|
74
|
-
worksheet = Worksheet.new(@io, :sst => sst, :auto_format => auto_format)
|
|
75
|
+
worksheet = Worksheet.new(@io, :sst => sst, :auto_format => auto_format, :columns => columns)
|
|
75
76
|
yield worksheet if block_given?
|
|
76
77
|
worksheet.close
|
|
77
78
|
|
|
@@ -104,7 +105,7 @@ module Xlsxtream
|
|
|
104
105
|
end
|
|
105
106
|
|
|
106
107
|
def write_workbook
|
|
107
|
-
rid = "rId0"
|
|
108
|
+
rid = String.new("rId0")
|
|
108
109
|
@io.add_file "xl/workbook.xml"
|
|
109
110
|
@io << XML.header
|
|
110
111
|
@io << XML.strip(<<-XML)
|
|
@@ -184,7 +185,7 @@ module Xlsxtream
|
|
|
184
185
|
end
|
|
185
186
|
|
|
186
187
|
def write_workbook_rels
|
|
187
|
-
rid = "rId0"
|
|
188
|
+
rid = String.new("rId0")
|
|
188
189
|
@io.add_file "xl/_rels/workbook.xml.rels"
|
|
189
190
|
@io << XML.header
|
|
190
191
|
@io << '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
|
data/lib/xlsxtream/worksheet.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
require "xlsxtream/xml"
|
|
3
3
|
require "xlsxtream/row"
|
|
4
4
|
|
|
@@ -28,6 +28,14 @@ module Xlsxtream
|
|
|
28
28
|
@io << XML.header
|
|
29
29
|
@io << XML.strip(<<-XML)
|
|
30
30
|
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
|
31
|
+
XML
|
|
32
|
+
|
|
33
|
+
columns = Array(@options[:columns])
|
|
34
|
+
unless columns.empty?
|
|
35
|
+
@io << Columns.new(columns).to_xml
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
@io << XML.strip(<<-XML)
|
|
31
39
|
<sheetData>
|
|
32
40
|
XML
|
|
33
41
|
end
|
data/lib/xlsxtream/xml.rb
CHANGED
data/xlsxtream.gemspec
CHANGED
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.0
|
|
4
|
+
version: 2.1.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: 2018-
|
|
11
|
+
date: 2018-07-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: zip_tricks
|
|
@@ -112,6 +112,7 @@ files:
|
|
|
112
112
|
- bin/console
|
|
113
113
|
- bin/setup
|
|
114
114
|
- lib/xlsxtream.rb
|
|
115
|
+
- lib/xlsxtream/columns.rb
|
|
115
116
|
- lib/xlsxtream/errors.rb
|
|
116
117
|
- lib/xlsxtream/io/directory.rb
|
|
117
118
|
- lib/xlsxtream/io/hash.rb
|
|
@@ -145,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
145
146
|
version: '0'
|
|
146
147
|
requirements: []
|
|
147
148
|
rubyforge_project:
|
|
148
|
-
rubygems_version: 2.7.
|
|
149
|
+
rubygems_version: 2.7.7
|
|
149
150
|
signing_key:
|
|
150
151
|
specification_version: 4
|
|
151
152
|
summary: Xlsxtream is a streaming XLSX spreadsheet writer
|