axlsx 1.0.12 → 1.0.14
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.
- data/README.md +165 -134
- data/examples/example.rb +133 -153
- data/lib/axlsx/#cfb.xlsx# +0 -0
- data/lib/axlsx/content_type/content_type.rb +23 -0
- data/lib/axlsx/content_type/default.rb +37 -0
- data/lib/axlsx/content_type/override.rb +37 -0
- data/lib/axlsx/doc_props/app.rb +178 -0
- data/lib/axlsx/doc_props/core.rb +34 -0
- data/lib/axlsx/drawing/axis.rb +93 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +136 -0
- data/lib/axlsx/drawing/bar_series.rb +64 -0
- data/lib/axlsx/drawing/cat_axis.rb +63 -0
- data/lib/axlsx/drawing/cat_axis_data.rb +35 -0
- data/lib/axlsx/drawing/chart.rb +193 -0
- data/lib/axlsx/drawing/drawing.rb +137 -0
- data/lib/axlsx/drawing/graphic_frame.rb +52 -0
- data/lib/axlsx/drawing/line_3D_chart.rb +114 -0
- data/lib/axlsx/drawing/line_series.rb +46 -0
- data/lib/axlsx/drawing/marker.rb +61 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
- data/lib/axlsx/drawing/pic.rb +153 -0
- data/lib/axlsx/drawing/picture_locking.rb +72 -0
- data/lib/axlsx/drawing/picture_locking.rb~ +36 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +41 -0
- data/lib/axlsx/drawing/pie_series.rb +56 -0
- data/lib/axlsx/drawing/scaling.rb +59 -0
- data/lib/axlsx/drawing/ser_axis.rb +45 -0
- data/lib/axlsx/drawing/series.rb +71 -0
- data/lib/axlsx/drawing/series_title.rb +22 -0
- data/lib/axlsx/drawing/title.rb +65 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +76 -0
- data/lib/axlsx/drawing/val_axis.rb +34 -0
- data/lib/axlsx/drawing/val_axis_data.rb +26 -0
- data/lib/axlsx/drawing/view_3D.rb +85 -0
- data/lib/axlsx/package.rb +223 -0
- data/lib/axlsx/rels/relationship.rb +44 -0
- data/lib/axlsx/rels/relationships.rb +25 -0
- data/lib/axlsx/stylesheet/border.rb +57 -0
- data/lib/axlsx/stylesheet/border_pr.rb +68 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +105 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +36 -0
- data/lib/axlsx/stylesheet/cell_style.rb +65 -0
- data/lib/axlsx/stylesheet/color.rb +69 -0
- data/lib/axlsx/stylesheet/fill.rb +32 -0
- data/lib/axlsx/stylesheet/font.rb +139 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +76 -0
- data/lib/axlsx/stylesheet/gradient_stop.rb +33 -0
- data/lib/axlsx/stylesheet/num_fmt.rb +63 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +66 -0
- data/lib/axlsx/stylesheet/styles.rb +298 -0
- data/lib/axlsx/stylesheet/table_style.rb +47 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +71 -0
- data/lib/axlsx/stylesheet/table_styles.rb +39 -0
- data/lib/axlsx/stylesheet/xf.rb +138 -0
- data/lib/axlsx/util/constants.rb +216 -0
- data/lib/axlsx/util/ms_off_crypto.rb +88 -0
- data/lib/axlsx/util/ms_off_crypto.rb~ +3 -0
- data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
- data/lib/axlsx/util/parser.rb +43 -0
- data/lib/axlsx/util/parser.rb~ +6 -0
- data/lib/axlsx/util/simple_typed_list.rb +160 -0
- data/lib/axlsx/util/validators.rb +132 -0
- data/lib/axlsx/version.rb +4 -0
- data/lib/axlsx/workbook/workbook.rb +161 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +350 -0
- data/lib/axlsx/workbook/worksheet/row.rb +107 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +335 -0
- data/lib/axlsx.rb +59 -0
- data/test/drawing/tc_axis.rb +1 -1
- data/test/drawing/tc_cat_axis.rb +1 -1
- data/test/drawing/tc_line_series.tc~ +34 -0
- data/test/drawing/tc_picture_locking.rb~ +77 -0
- data/test/tc_package.rb +10 -0
- data/test/workbook/worksheet/tc_cell.rb +15 -0
- data/test/workbook/worksheet/tc_worksheet.rb +22 -1
- metadata +117 -5
- data/examples/follow_20111202.xlsx +0 -0
data/examples/example.rb
CHANGED
|
@@ -1,204 +1,184 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
|
-
require 'axlsx'
|
|
3
|
+
require 'axlsx'
|
|
5
4
|
|
|
5
|
+
p = Axlsx::Package.new
|
|
6
|
+
wb = p.workbook
|
|
6
7
|
|
|
7
8
|
#A Simple Workbook
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
p.workbook.add_worksheet do |sheet|
|
|
9
|
+
|
|
10
|
+
wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
|
|
11
11
|
sheet.add_row ["First Column", "Second", "Third"]
|
|
12
12
|
sheet.add_row [1, 2, 3]
|
|
13
13
|
end
|
|
14
|
-
#p.workbook.date1904 = true
|
|
15
|
-
p.validate.each { |e| puts e.message }
|
|
16
|
-
p.serialize("example1.xlsx")
|
|
17
|
-
end
|
|
18
|
-
#Generating A Bar Chart
|
|
19
|
-
if ARGV.size==0 || ARGV.include?("2")
|
|
20
|
-
|
|
21
|
-
p = Axlsx::Package.new
|
|
22
|
-
p.workbook.add_worksheet do |sheet|
|
|
23
|
-
sheet.add_row ["A Simple Bar Chart"]
|
|
24
|
-
sheet.add_row ["First", "Second", "Third"]
|
|
25
|
-
sheet.add_row [1, 2, 3]
|
|
26
|
-
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17", :title=>sheet["A1"]) do |chart|
|
|
27
|
-
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"]
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
p.serialize("example2.xlsx")
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
#Generating A Pie Chart
|
|
34
|
-
if ARGV.size==0 || ARGV.include?("3")
|
|
35
|
-
|
|
36
|
-
p = Axlsx::Package.new
|
|
37
|
-
p.workbook.add_worksheet do |sheet|
|
|
38
|
-
sheet.add_row ["First", "Second", "Third", "Fourth"]
|
|
39
|
-
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
|
|
40
|
-
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title=>"example 3: Pie Chart") do |chart|
|
|
41
|
-
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
p.serialize("example3.xlsx")
|
|
45
|
-
|
|
46
|
-
end
|
|
47
14
|
|
|
48
15
|
#Using Custom Styles
|
|
49
|
-
if ARGV.size==0 || ARGV.include?("4")
|
|
50
|
-
|
|
51
|
-
p = Axlsx::Package.new
|
|
52
|
-
wb = p.workbook
|
|
53
|
-
black_cell = wb.styles.add_style :bg_color => "00", :fg_color => "FF", :sz=>14, :alignment => { :horizontal=> :center }
|
|
54
|
-
blue_cell = wb.styles.add_style :bg_color => "0000FF", :fg_color => "FF", :sz=>14, :alignment => { :horizontal=> :center }
|
|
55
|
-
wb.add_worksheet do |sheet|
|
|
56
|
-
sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
|
|
57
|
-
sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
|
|
58
|
-
end
|
|
59
|
-
p.serialize("example4.xlsx")
|
|
60
|
-
|
|
61
|
-
end
|
|
62
|
-
#Using Custom Formatting and date1904
|
|
63
|
-
if ARGV.size==0 || ARGV.include?("5")
|
|
64
16
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
|
|
73
|
-
sheet.add_row [Time.now, 0.2, 32], :style => [date, percent, padded]
|
|
74
|
-
end
|
|
75
|
-
p.serialize("example5.xlsx")
|
|
76
|
-
end
|
|
77
|
-
#Validation
|
|
78
|
-
if ARGV.size==0 || ARGV.include?("6")
|
|
79
|
-
|
|
80
|
-
p = Axlsx::Package.new
|
|
81
|
-
p.workbook.add_worksheet do |sheet|
|
|
82
|
-
sheet.add_row ["First", "Second", "Third"]
|
|
83
|
-
sheet.add_row [1, 2, 3]
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
p.validate.each do |error|
|
|
87
|
-
puts error.inspect
|
|
17
|
+
wb.styles do |s|
|
|
18
|
+
black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
|
|
19
|
+
blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
|
|
20
|
+
wb.add_worksheet(:name => "Custom Styles") do |sheet|
|
|
21
|
+
sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
|
|
22
|
+
sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
|
|
23
|
+
end
|
|
88
24
|
end
|
|
89
25
|
|
|
90
|
-
|
|
91
|
-
#Generating A Line Chart
|
|
92
|
-
if ARGV.size==0 || ARGV.include?("7")
|
|
26
|
+
##Using Custom Formatting and date1904
|
|
93
27
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
chart.add_series :data=>sheet.rows.last.cells[(1..-1)], :title=> sheet.rows.last.cells.first
|
|
28
|
+
wb.styles do |s|
|
|
29
|
+
date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
|
|
30
|
+
padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
|
|
31
|
+
percent = s.add_style(:format_code => "0000%", :border => Axlsx::STYLE_THIN_BORDER)
|
|
32
|
+
wb.date1904 = true # required for generation on mac
|
|
33
|
+
wb.add_worksheet(:name => "Formatting Data") do |sheet|
|
|
34
|
+
sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
|
|
35
|
+
sheet.add_row [Time.now, 0.2, 32], :style => [date, percent, padded]
|
|
103
36
|
end
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
p.serialize("example7.xlsx")
|
|
107
|
-
|
|
108
|
-
end
|
|
37
|
+
end
|
|
109
38
|
|
|
110
|
-
|
|
111
|
-
if ARGV.size==0 || ARGV.include?("8")
|
|
39
|
+
##Add an Image
|
|
112
40
|
|
|
113
|
-
|
|
114
|
-
p.workbook.add_worksheet do |sheet|
|
|
41
|
+
wb.add_worksheet(:name => "Images") do |sheet|
|
|
115
42
|
img = File.expand_path('examples/image1.jpeg')
|
|
116
|
-
sheet.add_image(:image_src => img, :noSelect=>true, :noMove=>true) do |image|
|
|
43
|
+
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
|
|
117
44
|
image.width=720
|
|
118
45
|
image.height=666
|
|
119
46
|
image.start_at 2, 2
|
|
120
47
|
end
|
|
121
48
|
end
|
|
122
|
-
p.serialize("example8.xlsx")
|
|
123
|
-
|
|
124
|
-
end
|
|
125
49
|
|
|
126
|
-
|
|
127
|
-
if ARGV.size==0 || ARGV.include?("9")
|
|
50
|
+
##Asian Language Support
|
|
128
51
|
|
|
129
|
-
|
|
130
|
-
p.workbook.add_worksheet do |sheet|
|
|
52
|
+
wb.add_worksheet(:name => "Unicode Support") do |sheet|
|
|
131
53
|
sheet.add_row ["日本語"]
|
|
132
54
|
sheet.add_row ["华语/華語"]
|
|
133
55
|
sheet.add_row ["한국어/조선말"]
|
|
134
56
|
end
|
|
135
|
-
p.serialize("example9.xlsx")
|
|
136
57
|
|
|
137
|
-
|
|
58
|
+
##Styling Columns
|
|
138
59
|
|
|
60
|
+
wb.styles do |s|
|
|
61
|
+
percent = s.add_style :num_fmt => 9
|
|
62
|
+
wb.add_worksheet(:name => "Styling Columns") do |sheet|
|
|
63
|
+
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
|
64
|
+
sheet.add_row [1, 2, 0.3, 4]
|
|
65
|
+
sheet.add_row [1, 2, 0.2, 4]
|
|
66
|
+
sheet.add_row [1, 2, 0.1, 4]
|
|
67
|
+
sheet.col_style 2, percent, :row_offset => 1
|
|
68
|
+
end
|
|
69
|
+
end
|
|
139
70
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
71
|
+
##Styling Rows
|
|
72
|
+
|
|
73
|
+
wb.styles do |s|
|
|
74
|
+
head = s.add_style :bg_color => "00", :fg_color => "FF"
|
|
75
|
+
percent = s.add_style :num_fmt => 9
|
|
76
|
+
wb.add_worksheet(:name => "Styling Rows") do |sheet|
|
|
77
|
+
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
|
78
|
+
sheet.add_row [1, 2, 0.3, 4]
|
|
79
|
+
sheet.add_row [1, 2, 0.2, 4]
|
|
80
|
+
sheet.add_row [1, 2, 0.1, 4]
|
|
81
|
+
sheet.col_style 2, percent, :row_offset => 1
|
|
82
|
+
sheet.row_style 0, head
|
|
83
|
+
end
|
|
150
84
|
end
|
|
151
|
-
p.workbook.worksheets.first.col_style 2, percent, :row_offset=>1
|
|
152
|
-
p.serialize("example10.xlsx")
|
|
153
85
|
|
|
154
|
-
|
|
86
|
+
##Styling Cell Overrides
|
|
87
|
+
|
|
88
|
+
wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
|
|
89
|
+
# cell level style overides when adding cells
|
|
90
|
+
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
|
|
91
|
+
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
|
92
|
+
# cell level style overrides via sheet range
|
|
93
|
+
sheet["A1:D1"].each { |c| c.color = "FF0000"}
|
|
94
|
+
sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
|
|
95
|
+
end
|
|
155
96
|
|
|
156
|
-
|
|
157
|
-
if ARGV.size==0 || ARGV.include?("11")
|
|
97
|
+
##Using formula
|
|
158
98
|
|
|
159
|
-
|
|
160
|
-
p.workbook.add_worksheet do |sheet|
|
|
99
|
+
wb.add_worksheet(:name => "Using Formulas") do |sheet|
|
|
161
100
|
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
|
162
|
-
sheet.add_row [1, 2,
|
|
163
|
-
sheet.add_row [1, 2, 0.2, 4]
|
|
164
|
-
sheet.add_row [1, 2, 0.1, 4]
|
|
101
|
+
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
|
165
102
|
end
|
|
166
|
-
head = p.workbook.styles.add_style :bg_color => "00", :fg_color=>"FF"
|
|
167
|
-
percent = p.workbook.styles.add_style :num_fmt => 9
|
|
168
|
-
p.workbook.worksheets.first.col_style 2, percent, :row_offset=>1
|
|
169
|
-
p.workbook.worksheets.first.row_style 0, head
|
|
170
|
-
p.serialize("example11.xlsx")
|
|
171
103
|
|
|
172
|
-
|
|
104
|
+
##Merging Cells.
|
|
173
105
|
|
|
174
|
-
|
|
175
|
-
|
|
106
|
+
wb.add_worksheet(:name => 'Merging Cells') do |sheet|
|
|
107
|
+
# cell level style overides when adding cells
|
|
108
|
+
sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
|
|
109
|
+
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
|
110
|
+
sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
|
|
111
|
+
sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
|
|
112
|
+
sheet.merge_cells("A4:C4")
|
|
113
|
+
sheet["A1:D1"].each { |c| c.color = "FF0000"}
|
|
114
|
+
sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
|
|
115
|
+
end
|
|
176
116
|
|
|
177
|
-
|
|
178
|
-
p.workbook.add_worksheet do |sheet|
|
|
179
|
-
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
|
180
|
-
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
|
181
|
-
end
|
|
182
|
-
p.serialize("example12.xlsx")
|
|
117
|
+
##Generating A Bar Chart
|
|
183
118
|
|
|
184
|
-
|
|
119
|
+
wb.add_worksheet(:name => "Bar Chart") do |sheet|
|
|
120
|
+
sheet.add_row ["A Simple Bar Chart"]
|
|
121
|
+
sheet.add_row ["First", "Second", "Third"]
|
|
122
|
+
sheet.add_row [1, 2, 3]
|
|
123
|
+
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
|
|
124
|
+
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
##Generating A Pie Chart
|
|
185
129
|
|
|
130
|
+
wb.add_worksheet(:name => "Pie Chart") do |sheet|
|
|
131
|
+
sheet.add_row ["First", "Second", "Third", "Fourth"]
|
|
132
|
+
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
|
|
133
|
+
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
|
|
134
|
+
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
|
|
135
|
+
end
|
|
136
|
+
end
|
|
186
137
|
|
|
187
|
-
|
|
188
|
-
if ARGV.size==0 || ARGV.include?("13")
|
|
138
|
+
##Data over time
|
|
189
139
|
|
|
190
|
-
|
|
191
|
-
p.workbook.add_worksheet(:name=>'My Worksheet') do |sheet|
|
|
140
|
+
wb.add_worksheet(:name=>'Charting Dates') do |sheet|
|
|
192
141
|
# cell level style overides when adding cells
|
|
193
|
-
sheet.add_row ['
|
|
194
|
-
sheet.add_row [
|
|
195
|
-
|
|
196
|
-
sheet[
|
|
142
|
+
sheet.add_row ['Date', 'Value'], :sz => 16
|
|
143
|
+
sheet.add_row [Time.now - (7*60*60*24), 3]
|
|
144
|
+
sheet.add_row [Time.now - (6*60*60*24), 7]
|
|
145
|
+
sheet.add_row [Time.now - (5*60*60*24), 18]
|
|
146
|
+
sheet.add_row [Time.now - (4*60*60*24), 1]
|
|
147
|
+
sheet.add_chart(Axlsx::Bar3DChart) do |chart|
|
|
148
|
+
chart.start_at "B7"
|
|
149
|
+
chart.end_at "H27"
|
|
150
|
+
chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
|
|
151
|
+
end
|
|
197
152
|
end
|
|
198
|
-
p.workbook['My Worksheet!A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
|
|
199
|
-
p.serialize("example13.xlsx")
|
|
200
153
|
|
|
201
|
-
|
|
154
|
+
##Generating A Line Chart
|
|
155
|
+
|
|
156
|
+
wb.add_worksheet(:name => "Line Chart") do |sheet|
|
|
157
|
+
sheet.add_row ["First", 1, 5, 7, 9]
|
|
158
|
+
sheet.add_row ["Second", 5, 2, 14, 9]
|
|
159
|
+
sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart|
|
|
160
|
+
chart.start_at 0, 2
|
|
161
|
+
chart.end_at 10, 15
|
|
162
|
+
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
|
|
163
|
+
chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
##Auto Filter
|
|
168
|
+
|
|
169
|
+
wb.add_worksheet(:name => "Auto Filter") do |sheet|
|
|
170
|
+
sheet.add_row ["Build Matrix"]
|
|
171
|
+
sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
|
|
172
|
+
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
|
|
173
|
+
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
|
174
|
+
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
|
175
|
+
sheet.auto_filter = "A2:D5"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
##Validate and Serialize
|
|
179
|
+
|
|
180
|
+
p.validate.each { |e| puts e.message }
|
|
181
|
+
p.serialize("example.xlsx")
|
|
202
182
|
|
|
203
183
|
|
|
204
184
|
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
require 'axlsx/content_type/default.rb'
|
|
3
|
+
require 'axlsx/content_type/override.rb'
|
|
4
|
+
|
|
5
|
+
# ContentTypes used in the package. This is automatcially managed by the package package.
|
|
6
|
+
class ContentType < SimpleTypedList
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
super [Override, Default]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Generates the xml document for [Content_Types].xml
|
|
13
|
+
# @return [String] The document as a string.
|
|
14
|
+
def to_xml()
|
|
15
|
+
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
|
|
16
|
+
xml.Types(:xmlns => Axlsx::XML_NS_T) {
|
|
17
|
+
each { |type| type.to_xml(xml) }
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
builder.to_xml
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
# An default content part. These parts are automatically created by for you based on the content of your package.
|
|
3
|
+
class Default
|
|
4
|
+
|
|
5
|
+
# The extension of the content type.
|
|
6
|
+
# @return [String]
|
|
7
|
+
attr_reader :Extension
|
|
8
|
+
|
|
9
|
+
# The type of content.
|
|
10
|
+
# @return [String]
|
|
11
|
+
attr_reader :ContentType
|
|
12
|
+
|
|
13
|
+
#Creates a new Default object
|
|
14
|
+
# @option options [String] Extension
|
|
15
|
+
# @option options [String] ContentType
|
|
16
|
+
# @raise [ArgumentError] An argument error is raised if both Extension and ContentType are not specified.
|
|
17
|
+
def initialize(options={})
|
|
18
|
+
raise ArgumentError, "Extension and ContentType are required" unless options[:Extension] && options[:ContentType]
|
|
19
|
+
options.each do |o|
|
|
20
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
# Sets the file extension for this content type.
|
|
24
|
+
def Extension=(v) Axlsx::validate_string v; @Extension = v end
|
|
25
|
+
|
|
26
|
+
# Sets the content type
|
|
27
|
+
# @see Axlsx#validate_content_type
|
|
28
|
+
def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
|
|
29
|
+
|
|
30
|
+
# Serializes the object to xml
|
|
31
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
|
32
|
+
# @return [String]
|
|
33
|
+
def to_xml(xml)
|
|
34
|
+
xml.Default(self.instance_values)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
# An override content part. These parts are automatically created by for you based on the content of your package.
|
|
3
|
+
class Override
|
|
4
|
+
|
|
5
|
+
# The type of content.
|
|
6
|
+
# @return [String]
|
|
7
|
+
attr_reader :ContentType
|
|
8
|
+
|
|
9
|
+
# The name and location of the part.
|
|
10
|
+
# @return [String]
|
|
11
|
+
attr_reader :PartName
|
|
12
|
+
|
|
13
|
+
#Creates a new Override object
|
|
14
|
+
# @option options [String] PartName
|
|
15
|
+
# @option options [String] ContentType
|
|
16
|
+
# @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
|
|
17
|
+
def initialize(options={})
|
|
18
|
+
raise ArgumentError, "PartName and ContentType are required" unless options[:PartName] && options[:ContentType]
|
|
19
|
+
options.each do |o|
|
|
20
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The name and location of the part.
|
|
25
|
+
def PartName=(v) Axlsx::validate_string v; @PartName = v end
|
|
26
|
+
|
|
27
|
+
# The content type.
|
|
28
|
+
# @see Axlsx#validate_content_type
|
|
29
|
+
def ContentType=(v) Axlsx::validate_content_type v; @ContentType = v end
|
|
30
|
+
|
|
31
|
+
# Serializes the Override object to xml
|
|
32
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
|
33
|
+
def to_xml(xml)
|
|
34
|
+
xml.Override(self.instance_values)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
module Axlsx
|
|
3
|
+
# App represents the app.xml document. The attributes for this object are primarily managed by the application the end user uses to edit the document. None of the attributes are required to serialize a valid xlsx object.
|
|
4
|
+
# @see shared-documentPropertiesExtended.xsd
|
|
5
|
+
# @note Support is not implemented for the following complex types:
|
|
6
|
+
#
|
|
7
|
+
# HeadingPairs (VectorVariant),
|
|
8
|
+
# TitlesOfParts (VectorLpstr),
|
|
9
|
+
# HLinks (VectorVariant),
|
|
10
|
+
# DigSig (DigSigBlob)
|
|
11
|
+
class App
|
|
12
|
+
|
|
13
|
+
# @return [String] The name of the document template.
|
|
14
|
+
attr_reader :Template
|
|
15
|
+
|
|
16
|
+
# @return [String] The name of the manager for the document.
|
|
17
|
+
attr_reader :Manager
|
|
18
|
+
|
|
19
|
+
# @return [String] The name of the company generating the document.
|
|
20
|
+
attr_reader :Company
|
|
21
|
+
|
|
22
|
+
# @return [Integer] The number of pages in the document.
|
|
23
|
+
attr_reader :Pages
|
|
24
|
+
|
|
25
|
+
# @return [Integer] The number of words in the document.
|
|
26
|
+
attr_reader :Words
|
|
27
|
+
|
|
28
|
+
# @return [Integer] The number of characters in the document.
|
|
29
|
+
attr_reader :Characters
|
|
30
|
+
|
|
31
|
+
# @return [String] The intended format of the presentation.
|
|
32
|
+
attr_reader :PresentationFormat
|
|
33
|
+
|
|
34
|
+
# @return [Integer] The number of lines in the document.
|
|
35
|
+
attr_reader :Lines
|
|
36
|
+
|
|
37
|
+
# @return [Integer] The number of paragraphs in the document
|
|
38
|
+
attr_reader :Paragraphs
|
|
39
|
+
|
|
40
|
+
# @return [Intger] The number of slides in the document.
|
|
41
|
+
attr_reader :Slides
|
|
42
|
+
|
|
43
|
+
# @return [Integer] The number of slides that have notes.
|
|
44
|
+
attr_reader :Notes
|
|
45
|
+
|
|
46
|
+
# @return [Integer] The total amount of time spent editing.
|
|
47
|
+
attr_reader :TotalTime
|
|
48
|
+
|
|
49
|
+
# @return [Integer] The number of hidden slides.
|
|
50
|
+
attr_reader :HiddenSlides
|
|
51
|
+
|
|
52
|
+
# @return [Integer] The total number multimedia clips
|
|
53
|
+
attr_reader :MMClips
|
|
54
|
+
|
|
55
|
+
# @return [Boolean] The display mode for the document thumbnail.
|
|
56
|
+
attr_reader :ScaleCrop
|
|
57
|
+
|
|
58
|
+
# @return [Boolean] The links in the document are up to date.
|
|
59
|
+
attr_reader :LinksUpToDate
|
|
60
|
+
|
|
61
|
+
# @return [Integer] The number of characters in the document including spaces.
|
|
62
|
+
attr_reader :CharactersWithSpaces
|
|
63
|
+
|
|
64
|
+
# @return [Boolean] Indicates if the document is shared.
|
|
65
|
+
attr_reader :ShareDoc
|
|
66
|
+
|
|
67
|
+
# @return [String] The base for hyper links in the document.
|
|
68
|
+
attr_reader :HyperLinkBase
|
|
69
|
+
|
|
70
|
+
# @return [Boolean] Indicates that the hyper links in the document have been changed.
|
|
71
|
+
attr_reader :HyperlinksChanged
|
|
72
|
+
|
|
73
|
+
# @return [String] The name of the application
|
|
74
|
+
attr_reader :Application
|
|
75
|
+
|
|
76
|
+
# @return [String] The version of the application.
|
|
77
|
+
attr_reader :AppVersion
|
|
78
|
+
|
|
79
|
+
# @return [Integer] Document security
|
|
80
|
+
attr_reader :DocSecurity
|
|
81
|
+
|
|
82
|
+
# Creates an App object
|
|
83
|
+
# @option options [String] Template
|
|
84
|
+
# @option options [String] Manager
|
|
85
|
+
# @option options [Integer] Pages
|
|
86
|
+
# @option options [Integer] Words
|
|
87
|
+
# @option options [Integer] Characters
|
|
88
|
+
# @option options [String] PresentationFormat
|
|
89
|
+
# @option options [Integer] Lines
|
|
90
|
+
# @option options [Integer] Paragraphs
|
|
91
|
+
# @option options [Integer] Slides
|
|
92
|
+
# @option options [Integer] Notes
|
|
93
|
+
# @option options [Integer] TotalTime
|
|
94
|
+
# @option options [Integer] HiddenSlides
|
|
95
|
+
# @option options [Integer] MMClips
|
|
96
|
+
# @option options [Boolean] ScaleCrop
|
|
97
|
+
# @option options [Boolean] LinksUpToDate
|
|
98
|
+
# @option options [Integer] CharactersWithSpaces
|
|
99
|
+
# @option options [Boolean] ShareDoc
|
|
100
|
+
# @option options [String] HyperLinkBase
|
|
101
|
+
# @option options [String] HyperlinksChanged
|
|
102
|
+
# @option options [String] Application
|
|
103
|
+
# @option options [String] AppVersion
|
|
104
|
+
# @option options [Integer] DocSecurity
|
|
105
|
+
def initialize(options={})
|
|
106
|
+
options.each do |o|
|
|
107
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Sets the Template property of your app.xml file
|
|
112
|
+
def Template=(v) Axlsx::validate_string v; @Template = v; end
|
|
113
|
+
|
|
114
|
+
# Sets the Manager property of your app.xml file
|
|
115
|
+
def Manager=(v) Axlsx::validate_string v; @Manager = v; end
|
|
116
|
+
|
|
117
|
+
# Sets the Company property of your app.xml file
|
|
118
|
+
def Company=(v) Axlsx::validate_string v; @Company = v; end
|
|
119
|
+
|
|
120
|
+
# Sets the Pages property of your app.xml file
|
|
121
|
+
def Pages=(v) Axlsx::validate_int v; @Pages = v; end
|
|
122
|
+
|
|
123
|
+
# Sets the Words property of your app.xml file
|
|
124
|
+
def Words=(v) Axlsx::validate_int v; @Words = v; end
|
|
125
|
+
|
|
126
|
+
# Sets the Characters property of your app.xml file
|
|
127
|
+
def Characters=(v) Axlsx::validate_int v; @Characters = v; end
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# Sets the PresentationFormat property of your app.xml file
|
|
131
|
+
def PresentationFormat=(v) Axlsx::validate_string v; @PresentationFormat = v; end
|
|
132
|
+
# Sets the Lines property of your app.xml file
|
|
133
|
+
def Lines=(v) Axlsx::validate_int v; @Lines = v; end
|
|
134
|
+
# Sets the Paragraphs property of your app.xml file
|
|
135
|
+
def Paragraphs=(v) Axlsx::validate_int v; @Paragraphs = v; end
|
|
136
|
+
# Sets the Slides property of your app.xml file
|
|
137
|
+
def Slides=(v) Axlsx::validate_int v; @Slides = v; end
|
|
138
|
+
# Sets the Notes property of your app.xml file
|
|
139
|
+
def Notes=(v) Axlsx::validate_int v; @Notes = v; end
|
|
140
|
+
# Sets the TotalTime property of your app.xml file
|
|
141
|
+
def TotalTime=(v) Axlsx::validate_int v; @TotalTime = v; end
|
|
142
|
+
# Sets the HiddenSlides property of your app.xml file
|
|
143
|
+
def HiddenSlides=(v) Axlsx::validate_int v; @HiddenSlides = v; end
|
|
144
|
+
# Sets the MMClips property of your app.xml file
|
|
145
|
+
def MMClips=(v) Axlsx::validate_int v; @MMClips = v; end
|
|
146
|
+
# Sets the ScaleCrop property of your app.xml file
|
|
147
|
+
def ScaleCrop=(v) Axlsx::validate_boolean v; @ScaleCrop = v; end
|
|
148
|
+
# Sets the LinksUpToDate property of your app.xml file
|
|
149
|
+
def LinksUpToDate=(v) Axlsx::validate_boolean v; @LinksUpToDate = v; end
|
|
150
|
+
# Sets the CharactersWithSpaces property of your app.xml file
|
|
151
|
+
def CharactersWithSpaces=(v) Axlsx::validate_int v; @CharactersWithSpaces = v; end
|
|
152
|
+
# Sets the ShareDoc property of your app.xml file
|
|
153
|
+
def ShareDoc=(v) Axlsx::validate_boolean v; @ShareDoc = v; end
|
|
154
|
+
# Sets the HyperLinkBase property of your app.xml file
|
|
155
|
+
def HyperLinkBase=(v) Axlsx::validate_string v; @HyperLinkBase = v; end
|
|
156
|
+
# Sets the HyperLinksChanged property of your app.xml file
|
|
157
|
+
def HyperlinksChanged=(v) Axlsx::validate_boolean v; @HyperlinksChanged = v; end
|
|
158
|
+
# Sets the Application property of your app.xml file
|
|
159
|
+
def Application=(v) Axlsx::validate_string v; @Application = v; end
|
|
160
|
+
# Sets the AppVersion property of your app.xml file
|
|
161
|
+
def AppVersion=(v) Axlsx::validate_string v; @AppVersion = v; end
|
|
162
|
+
# Sets the DocSecurity property of your app.xml file
|
|
163
|
+
def DocSecurity=(v) Axlsx::validate_int v; @DocSecurity = v; end
|
|
164
|
+
|
|
165
|
+
# Generate an app.xml document
|
|
166
|
+
# @return [String] The document as a string
|
|
167
|
+
def to_xml()
|
|
168
|
+
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
|
|
169
|
+
xml.send(:Properties, :xmlns => APP_NS, :'xmlns:vt' => APP_NS_VT) {
|
|
170
|
+
self.instance_values.each do |name, value|
|
|
171
|
+
xml.send(name, value)
|
|
172
|
+
end
|
|
173
|
+
}
|
|
174
|
+
end
|
|
175
|
+
builder.to_xml
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
# The core object for the package.
|
|
3
|
+
# @note Packages manage their own core object.
|
|
4
|
+
# @see Package#core
|
|
5
|
+
class Core
|
|
6
|
+
# The author of the document. By default this is 'axlsx'
|
|
7
|
+
# @return [String]
|
|
8
|
+
attr_accessor :creator
|
|
9
|
+
|
|
10
|
+
# Creates a new Core object.
|
|
11
|
+
# @option options [String] creator
|
|
12
|
+
def initialize(options={})
|
|
13
|
+
@creator = options[:creator] || 'axlsx'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Serializes the core object. The created dcterms item is set to the current time when this method is called.
|
|
17
|
+
# @return [String]
|
|
18
|
+
def to_xml()
|
|
19
|
+
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
|
|
20
|
+
xml.send('cp:coreProperties',
|
|
21
|
+
:"xmlns:cp" => CORE_NS,
|
|
22
|
+
:'xmlns:dc' => CORE_NS_DC,
|
|
23
|
+
:'xmlns:dcmitype'=>CORE_NS_DCMIT,
|
|
24
|
+
:'xmlns:dcterms'=>CORE_NS_DCT,
|
|
25
|
+
:'xmlns:xsi'=>CORE_NS_XSI) {
|
|
26
|
+
xml['dc'].creator self.creator
|
|
27
|
+
xml['dcterms'].created Time.now.strftime('%Y-%m-%dT%H:%M:%S'), :'xsi:type'=>"dcterms:W3CDTF"
|
|
28
|
+
xml['cp'].revision 0
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
builder.to_xml
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|