openxml-xlsx 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -3
- data/lib/xlsx.rb +3 -3
- data/lib/xlsx/elements/alignment.rb +3 -3
- data/lib/xlsx/elements/border.rb +3 -3
- data/lib/xlsx/elements/border_component.rb +2 -2
- data/lib/xlsx/elements/cell.rb +15 -15
- data/lib/xlsx/elements/defined_name.rb +2 -2
- data/lib/xlsx/elements/font.rb +2 -2
- data/lib/xlsx/elements/indexed_color.rb +2 -2
- data/lib/xlsx/elements/number_format.rb +7 -7
- data/lib/xlsx/elements/pattern_fill.rb +2 -2
- data/lib/xlsx/elements/relationship.rb +3 -3
- data/lib/xlsx/elements/row.rb +5 -5
- data/lib/xlsx/elements/theme_color.rb +2 -2
- data/lib/xlsx/package.rb +2 -2
- data/lib/xlsx/parts/shared_strings.rb +3 -3
- data/lib/xlsx/parts/stylesheet.rb +2 -2
- data/lib/xlsx/parts/workbook.rb +2 -2
- data/lib/xlsx/parts/worksheet.rb +2 -2
- data/lib/xlsx/version.rb +1 -1
- data/xlsx.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 374ce4f77d6e68c32dcd699a9b7cc71c159c55e1
|
4
|
+
data.tar.gz: 99d760a114ddd00435d05e7912e6ff77e8443b8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e79d23a902a1a7957e76f58e53f22617eaace826c94a802ed11e24f519622e9788c09488c5be5a6407b5806d4d5a1b013c7a60610126841d1995b735f98b223
|
7
|
+
data.tar.gz: c672ecec03e616ce3bf31f170740cbb6227908c1c74198c378d5fd1ce54db98aaef5f7d164221bd5e1293465b84539c835ac1f5b3309fe8c1859c01d082c31fb
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openxml-xlsx (0.1.
|
4
|
+
openxml-xlsx (0.1.2)
|
5
5
|
nokogiri
|
6
|
-
open_xml_package (= 0.
|
6
|
+
open_xml_package (= 0.2.0.beta1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -15,9 +15,11 @@ GEM
|
|
15
15
|
multi_json (1.7.2)
|
16
16
|
nokogiri (1.6.6.2)
|
17
17
|
mini_portile (~> 0.6.0)
|
18
|
-
open_xml_package (0.
|
18
|
+
open_xml_package (0.2.0.beta1)
|
19
19
|
nokogiri
|
20
|
+
ox
|
20
21
|
rubyzip (~> 1.1.0)
|
22
|
+
ox (2.2.2)
|
21
23
|
pry (0.9.12)
|
22
24
|
coderay (~> 1.0.5)
|
23
25
|
method_source (~> 0.8)
|
data/lib/xlsx.rb
CHANGED
@@ -6,7 +6,7 @@ module Xlsx
|
|
6
6
|
REL_CALC_CHAIN = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain".freeze
|
7
7
|
REL_THEME = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme".freeze
|
8
8
|
REL_TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table".freeze
|
9
|
-
|
9
|
+
|
10
10
|
TYPE_WORKBOOK = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml".freeze
|
11
11
|
TYPE_WORKSHEET = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml".freeze
|
12
12
|
TYPE_THEME = "application/vnd.openxmlformats-officedocument.theme+xml".freeze
|
@@ -16,11 +16,11 @@ module Xlsx
|
|
16
16
|
TYPE_CORE_PROPS = "application/vnd.openxmlformats-package.core-properties+xml".freeze
|
17
17
|
TYPE_APP_PROPS = "application/vnd.openxmlformats-officedocument.extended-properties+xml".freeze
|
18
18
|
TYPE_TABLE = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml".freeze
|
19
|
-
|
19
|
+
|
20
20
|
def self.index!(collection, item)
|
21
21
|
collection.index(item) || collection.push(item).length - 1
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
25
|
|
26
26
|
require "xlsx/elements"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Xlsx
|
2
2
|
module Elements
|
3
3
|
class Alignment < Struct.new(:horizontal, :vertical, :indent, :wrapText)
|
4
|
-
|
4
|
+
|
5
5
|
def attributes
|
6
6
|
{}.tap do |attrs|
|
7
7
|
attrs[:horizontal] = horizontal if horizontal
|
@@ -10,11 +10,11 @@ module Xlsx
|
|
10
10
|
attrs[:wrapText] = wrapText if wrapText
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def to_xml(xml)
|
15
15
|
xml.alignment(attributes)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/xlsx/elements/border.rb
CHANGED
@@ -2,7 +2,7 @@ module Xlsx
|
|
2
2
|
module Elements
|
3
3
|
class Border
|
4
4
|
attr_reader :left_component, :right_component, :top_component, :bottom_component, :diagonal_component
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(options={})
|
7
7
|
@left_component = options.fetch(:left, BorderComponent.new)
|
8
8
|
@right_component = options.fetch(:right, BorderComponent.new)
|
@@ -10,7 +10,7 @@ module Xlsx
|
|
10
10
|
@bottom_component = options.fetch(:bottom, BorderComponent.new)
|
11
11
|
@diagonal_component = options.fetch(:diagonal, BorderComponent.new)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def to_xml(xml)
|
15
15
|
xml.border do
|
16
16
|
left_component.to_xml("left", xml)
|
@@ -20,7 +20,7 @@ module Xlsx
|
|
20
20
|
diagonal_component.to_xml("diagonal", xml)
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Xlsx
|
2
2
|
module Elements
|
3
3
|
class BorderComponent < Struct.new(:style, :color)
|
4
|
-
|
4
|
+
|
5
5
|
def to_xml(name, xml)
|
6
6
|
if style && color
|
7
7
|
xml.public_send(name, style: style) do
|
@@ -13,7 +13,7 @@ module Xlsx
|
|
13
13
|
xml.public_send(name)
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/xlsx/elements/cell.rb
CHANGED
@@ -4,7 +4,7 @@ module Xlsx
|
|
4
4
|
module Elements
|
5
5
|
class Cell
|
6
6
|
attr_reader :row, :column, :value, :type, :style, :formula
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(row, options={})
|
9
9
|
@row = row
|
10
10
|
@column = options.fetch(:column)
|
@@ -25,11 +25,11 @@ module Xlsx
|
|
25
25
|
@style = package.style_ref(options[:style]) if options.key? :style
|
26
26
|
@formula = options[:formula]
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def id
|
30
30
|
"#{column_letter}#{row.number}"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def column_letter
|
34
34
|
bytes = []
|
35
35
|
remaining = column
|
@@ -39,41 +39,41 @@ module Xlsx
|
|
39
39
|
end
|
40
40
|
bytes.pack "c*"
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def worksheet
|
44
44
|
row.worksheet
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def workbook
|
48
48
|
worksheet.workbook
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def package
|
52
52
|
workbook.package
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def to_xml(xml)
|
56
56
|
attributes = {"r" => id}
|
57
57
|
attributes.merge!("s" => style) if style
|
58
58
|
attributes.merge!("t" => "s") if type == :string
|
59
|
-
|
59
|
+
|
60
60
|
value = self.value
|
61
61
|
value = string_id if type == :string
|
62
62
|
value = serial_date if type == :date
|
63
63
|
value = serial_time if type == :time
|
64
|
-
|
64
|
+
|
65
65
|
xml.c(attributes) do
|
66
66
|
xml.f formula if formula
|
67
67
|
xml.v value if value
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
private
|
72
72
|
attr_reader :string_id, :serial_date, :serial_time
|
73
|
-
|
73
|
+
|
74
74
|
EXCEL_ANCHOR_DATE = Date.new(1900, 1, 1).freeze
|
75
75
|
SECONDS_PER_DAY = 86400.freeze
|
76
|
-
|
76
|
+
|
77
77
|
def to_serial_date(date)
|
78
78
|
# Excel stores dates as the number of days since 1900-Jan-0
|
79
79
|
# Excel behaves as if 1900 was a leap year, so the number is
|
@@ -81,14 +81,14 @@ module Xlsx
|
|
81
81
|
# http://www.cpearson.com/excel/datetime.htm
|
82
82
|
(date - EXCEL_ANCHOR_DATE).to_i + 2
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def to_serial_time(time)
|
86
86
|
date = to_serial_date(time.to_date)
|
87
|
-
|
87
|
+
|
88
88
|
seconds_since_midnight = time.hour * 3600 + time.min * 60 + time.sec
|
89
89
|
date + (seconds_since_midnight.to_f / SECONDS_PER_DAY)
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
data/lib/xlsx/elements/font.rb
CHANGED
@@ -7,7 +7,7 @@ module Xlsx
|
|
7
7
|
DECIMAL = ImpliedNumberFormat.new(2).freeze # 0.00
|
8
8
|
INTEGER_THOUSANDS = ImpliedNumberFormat.new(3).freeze # #,##0
|
9
9
|
DECIMAL_THOUSANDS = ImpliedNumberFormat.new(4).freeze # #,##0.00
|
10
|
-
|
10
|
+
|
11
11
|
INTEGER_PERCENT = ImpliedNumberFormat.new(9).freeze # 0%
|
12
12
|
DECIMAL_PERCENT = ImpliedNumberFormat.new(10).freeze # 0.00%
|
13
13
|
SCIENTIFIC = ImpliedNumberFormat.new(11).freeze # 0.00E+00
|
@@ -22,24 +22,24 @@ module Xlsx
|
|
22
22
|
TIME_ALT = ImpliedNumberFormat.new(20).freeze # h:mm
|
23
23
|
TIME_SECONDS_ALT = ImpliedNumberFormat.new(21).freeze # h:mm:ss
|
24
24
|
DATETIME = ImpliedNumberFormat.new(22).freeze # m/d/yy h:mm
|
25
|
-
|
25
|
+
|
26
26
|
FINANCIAL_INTEGER = ImpliedNumberFormat.new(37).freeze # #,##0 ;(#,##0)
|
27
27
|
FINANCIAL_INTEGER_RED = ImpliedNumberFormat.new(38).freeze # #,##0 ;[Red](#,##0)
|
28
28
|
FINANCIAL_DECIMAL = ImpliedNumberFormat.new(39).freeze # #,##0.00 ;(#,##0.00)
|
29
29
|
FINANCIAL_DECIMAL_RED = ImpliedNumberFormat.new(40).freeze # #,##0.00 ;[Red](#,##0.00)
|
30
|
-
|
30
|
+
|
31
31
|
INTERVAL = ImpliedNumberFormat.new(45).freeze # mm:ss
|
32
32
|
INTERVAL_HOURS = ImpliedNumberFormat.new(46).freeze # [h]:mm:ss
|
33
33
|
TIMESTAMP = ImpliedNumberFormat.new(47).freeze # mmss.0
|
34
34
|
# SCIENTIFIC_ALT = ImpliedNumberFormat.new(48).freeze # ##0.0E+0
|
35
35
|
# UNKONWN = ImpliedNumberFormat.new(49).freeze # @
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
|
37
|
+
|
38
|
+
|
39
39
|
def to_xml(id, xml)
|
40
40
|
xml.numFmt(numFmtId: id, formatCode: format)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Xlsx
|
2
2
|
module Elements
|
3
3
|
class PatternFill < Struct.new(:type, :foreground_color, :background_color)
|
4
|
-
|
4
|
+
|
5
5
|
def to_xml(xml)
|
6
6
|
xml.fill do
|
7
7
|
xml.patternFill(patternType: type) do
|
@@ -12,7 +12,7 @@ module Xlsx
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -3,16 +3,16 @@ require "securerandom"
|
|
3
3
|
module Xlsx
|
4
4
|
module Elements
|
5
5
|
class Relationship < Struct.new(:type, :target, :id)
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(type, target, id=nil)
|
8
8
|
id ||= "R#{SecureRandom.hex}"
|
9
9
|
super type, target, id
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def to_xml(xml)
|
13
13
|
xml.Relationship("Id" => id, "Type" => type, "Target" => target)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/xlsx/elements/row.rb
CHANGED
@@ -2,23 +2,23 @@ module Xlsx
|
|
2
2
|
module Elements
|
3
3
|
class Row
|
4
4
|
attr_reader :worksheet, :number, :height, :hidden, :cells
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(worksheet, options={})
|
7
7
|
@worksheet = worksheet
|
8
8
|
@number = options.fetch(:number)
|
9
9
|
@height = options[:height]
|
10
10
|
@hidden = options[:hidden]
|
11
11
|
@cells = []
|
12
|
-
|
12
|
+
|
13
13
|
Array(options[:cells]).each do |attributes|
|
14
14
|
add_cell attributes
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def add_cell(attributes)
|
19
19
|
cells.push Xlsx::Elements::Cell.new(self, attributes)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def to_xml(xml)
|
23
23
|
attributes = {"r" => number}
|
24
24
|
attributes.merge!("ht" => height, "customHeight" => 1) if height
|
@@ -29,7 +29,7 @@ module Xlsx
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/xlsx/package.rb
CHANGED
@@ -19,7 +19,7 @@ module Xlsx
|
|
19
19
|
def initialize
|
20
20
|
super
|
21
21
|
rels.add_relationship REL_DOCUMENT, "xl/workbook.xml"
|
22
|
-
|
22
|
+
|
23
23
|
@xl_rels = OpenXml::Parts::Rels.new([
|
24
24
|
{ "Type" => REL_SHARED_STRINGS, "Target" => "sharedStrings.xml" },
|
25
25
|
{ "Type" => REL_STYLES, "Target" => "styles.xml" }
|
@@ -27,7 +27,7 @@ module Xlsx
|
|
27
27
|
@shared_strings = Xlsx::Parts::SharedStrings.new
|
28
28
|
@stylesheet = Xlsx::Parts::Stylesheet.new
|
29
29
|
@workbook = Xlsx::Parts::Workbook.new(self)
|
30
|
-
|
30
|
+
|
31
31
|
# docProps/app.xml
|
32
32
|
# docProps/core.xml
|
33
33
|
add_part "xl/_rels/workbook.xml.rels", xl_rels
|
@@ -4,17 +4,17 @@ module Xlsx
|
|
4
4
|
attr_reader :strings
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
@strings = []
|
7
|
+
@strings = Hash.new { |hash, key| hash[key] = hash.length }
|
8
8
|
end
|
9
9
|
|
10
10
|
def reference_of(string)
|
11
|
-
|
11
|
+
strings[string]
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_xml
|
15
15
|
build_standalone_xml do |xml|
|
16
16
|
xml.sst(xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main", uniqueCount: strings.length) do
|
17
|
-
strings.each do |string|
|
17
|
+
strings.each do |string, i|
|
18
18
|
xml.si { xml.t(string) }
|
19
19
|
end
|
20
20
|
end
|
@@ -23,14 +23,14 @@ module Xlsx
|
|
23
23
|
options[:font_id] = Xlsx.index!(fonts, options[:font]) if options.key? :font
|
24
24
|
options[:fill_id] = Xlsx.index!(fills, options[:fill]) if options.key? :fill
|
25
25
|
options[:border_id] = Xlsx.index!(borders, options[:border]) if options.key? :border
|
26
|
-
|
26
|
+
|
27
27
|
style = Style.new(
|
28
28
|
options.fetch(:format_id, 0),
|
29
29
|
options.fetch(:font_id, 0),
|
30
30
|
options.fetch(:fill_id, 0),
|
31
31
|
options.fetch(:border_id, 0),
|
32
32
|
options.fetch(:alignment, nil))
|
33
|
-
|
33
|
+
|
34
34
|
Xlsx.index!(styles, style)
|
35
35
|
end
|
36
36
|
|
data/lib/xlsx/parts/workbook.rb
CHANGED
@@ -27,13 +27,13 @@ module Xlsx
|
|
27
27
|
package.add_part "xl/tables/#{table.filename}", table
|
28
28
|
tables.push table
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def add_defined_names(*defined_names)
|
32
32
|
defined_names.flatten.each do |attributes|
|
33
33
|
add_defined_name attributes
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def add_defined_name(attributes)
|
38
38
|
defined_names.push Xlsx::Elements::DefinedName.new(attributes[:name], attributes[:formula])
|
39
39
|
end
|
data/lib/xlsx/parts/worksheet.rb
CHANGED
@@ -27,11 +27,11 @@ module Xlsx
|
|
27
27
|
def add_row(attributes)
|
28
28
|
rows.push Xlsx::Elements::Row.new(self, attributes)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def merge_cells(*ranges)
|
32
32
|
ranges.each { |range| cell_ranges.push range }
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def add_table(id, name, ref, columns)
|
36
36
|
table = Xlsx::Parts::Table.new(id, name, ref, columns)
|
37
37
|
rels.add_relationship(REL_TABLE, "../tables/#{table.filename}")
|
data/lib/xlsx/version.rb
CHANGED
data/xlsx.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.required_ruby_version = "~> 2.0"
|
23
23
|
spec.add_dependency "nokogiri"
|
24
|
-
spec.add_dependency "open_xml_package", "0.
|
24
|
+
spec.add_dependency "open_xml_package", "0.2.0.beta1"
|
25
25
|
|
26
26
|
spec.add_development_dependency "pry"
|
27
27
|
spec.add_development_dependency "rspec"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openxml-xlsx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.2.0.beta1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.2.0.beta1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.4.8
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: Using a simple API, create xlsx files programmatically
|