axlsx 1.0.17 → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,24 +2,24 @@ Axlsx: Office Open XML Spreadsheet Generation
2
2
  ====================================
3
3
  [![Build Status](https://secure.travis-ci.org/randym/axlsx.png)](http://travis-ci.org/randym/axlsx/)
4
4
 
5
- **IRC**: [irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
6
- **Git**: [http://github.com/randym/axlsx](http://github.com/randym/axlsx)
7
- **Author**: Randy Morgan
8
- **Copyright**: 2011
9
- **License**: MIT License
10
- **Latest Version**: 1.0.17
11
- **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
5
+ **IRC**: [irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
6
+ **Git**: [http://github.com/randym/axlsx](http://github.com/randym/axlsx)
7
+ **Author**: Randy Morgan
8
+ **Copyright**: 2011
9
+ **License**: MIT License
10
+ **Latest Version**: 1.0.18
11
+ **Ruby Version**: 1.8.7, 1.9.2, 1.9.3
12
12
 
13
- **Release Date**: February 14th 2012
13
+ **Release Date**: March 5th 2012
14
14
 
15
15
  Synopsis
16
16
  --------
17
17
 
18
18
  Axlsx is an Office Open XML Spreadsheet generator for the Ruby programming language.
19
- With Axlsx you can create excel worksheets with charts, images (with links), automated and fixed column widths, customizable styles, functions, merged cells, auto filters, file adn stream serialization as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.
19
+ With Axlsx you can create excel worksheets with charts, images (with links), automated and fixed column widths, customizable styles, functions, merged cells, auto filters, file and stream serialization as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.
20
20
 
21
21
  If you are working in rails, or with active record see:
22
- http://github.com/randym/acts_as_xlsx
22
+ http://github.com/randym/acts_as_xlsx
23
23
 
24
24
  There are guides for using axlsx and acts_as_xlsx here:
25
25
  [http://axlsx.blogspot.com](http://axlsx.blogspot.com)
@@ -31,18 +31,18 @@ I'd really like to get rid of the depenency on RMagick in this gem. RMagic is be
31
31
 
32
32
  Feature List
33
33
  ------------
34
-
34
+
35
35
  **1. Author xlsx documents: Axlsx is made to let you easily and quickly generate profesional xlsx based reports that can be validated before serialiation.
36
36
 
37
37
  **2. Generate 3D Pie, Line and Bar Charts: With Axlsx chart generation and management is as easy as a few lines of code. You can build charts based off data in your worksheet or generate charts without any data in your sheet at all.
38
-
38
+
39
39
  **3. Custom Styles: With guaranteed document validity, you can style borders, alignment, fills, fonts, and number formats in a single line of code. Those styles can be applied to an entire row, or a single cell anywhere in your workbook.
40
40
 
41
- **4. Automatic type support: Axlsx will automatically determine the type of data you are generating. In this release Float, Integer, String and Time types are automatically identified and serialized to your spreadsheet.
41
+ **4. Automatic type support: Axlsx will automatically determine the type of data you are generating. In this release Float, Integer, String, Date, Time and Boolean types are automatically identified and serialized to your spreadsheet.
42
42
 
43
43
  **5. Automatic and fixed column widths: Axlsx will automatically determine the appropriate width for your columns based on the content in the worksheet, or use any value you specify for the really funky stuff.
44
44
 
45
- **6. Support for automatically formatted 1904 and 1900 epocs configurable in the workbook.
45
+ **6. Support for automatically formatted 1904 and 1900 epochs configurable in the workbook.
46
46
 
47
47
  **7. Add jpg, gif and png images to worksheets with hyperlinks
48
48
 
@@ -60,13 +60,15 @@ Feature List
60
60
 
61
61
  **14. Output to file or StringIO
62
62
 
63
+ **15. Support for page margins
64
+
63
65
  Installing
64
66
  ----------
65
67
 
66
68
  To install Axlsx, use the following command:
67
69
 
68
70
  $ gem install axlsx
69
-
71
+
70
72
  #Usage
71
73
  ------
72
74
 
@@ -82,14 +84,14 @@ To install Axlsx, use the following command:
82
84
  sheet.add_row [1, 2, 3]
83
85
  end
84
86
 
85
- ##Using Custom Styles
87
+ ##Using Custom Styles and Row Heights
86
88
 
87
89
  wb.styles do |s|
88
90
  black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
89
91
  blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
90
92
  wb.add_worksheet(:name => "Custom Styles") do |sheet|
91
93
  sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
92
- sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
94
+ sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER, :height => 20
93
95
  end
94
96
  end
95
97
 
@@ -110,25 +112,25 @@ To install Axlsx, use the following command:
110
112
  ##Add an Image
111
113
 
112
114
  wb.add_worksheet(:name => "Images") do |sheet|
113
- img = File.expand_path('examples/image1.jpeg')
115
+ img = File.expand_path('examples/image1.jpeg')
114
116
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
115
117
  image.width=720
116
118
  image.height=666
117
119
  image.start_at 2, 2
118
120
  end
119
- end
121
+ end
120
122
 
121
123
  ##Add an Image with a hyperlink
122
124
 
123
125
  wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
124
- img = File.expand_path('examples/image1.jpeg')
126
+ img = File.expand_path('examples/image1.jpeg')
125
127
  sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
126
128
  image.width=720
127
129
  image.height=666
128
130
  image.hyperlink.tooltip = "Labeled Link"
129
131
  image.start_at 2, 2
130
132
  end
131
- end
133
+ end
132
134
 
133
135
  ##Asian Language Support
134
136
 
@@ -136,7 +138,7 @@ To install Axlsx, use the following command:
136
138
  sheet.add_row ["日本語"]
137
139
  sheet.add_row ["华语/華語"]
138
140
  sheet.add_row ["한국어/조선말"]
139
- end
141
+ end
140
142
 
141
143
  ##Styling Columns
142
144
 
@@ -175,7 +177,7 @@ To install Axlsx, use the following command:
175
177
  # cell level style overrides via sheet range
176
178
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
177
179
  sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
178
- end
180
+ end
179
181
 
180
182
  ##Using formula
181
183
 
@@ -184,6 +186,13 @@ To install Axlsx, use the following command:
184
186
  sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
185
187
  end
186
188
 
189
+ ##Automatic cell types
190
+
191
+ wb.add_worksheet(:name => "Automatic cell types") do |sheet|
192
+ sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
193
+ sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1]
194
+ end
195
+
187
196
  ##Merging Cells.
188
197
 
189
198
  wb.add_worksheet(:name => 'Merging Cells') do |sheet|
@@ -195,7 +204,7 @@ To install Axlsx, use the following command:
195
204
  sheet.merge_cells("A4:C4")
196
205
  sheet["A1:D1"].each { |c| c.color = "FF0000"}
197
206
  sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
198
- end
207
+ end
199
208
 
200
209
  ##Generating A Bar Chart
201
210
 
@@ -206,7 +215,7 @@ To install Axlsx, use the following command:
206
215
  sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
207
216
  chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
208
217
  end
209
- end
218
+ end
210
219
 
211
220
  ##Generating A Pie Chart
212
221
 
@@ -216,7 +225,7 @@ To install Axlsx, use the following command:
216
225
  sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
217
226
  chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
218
227
  end
219
- end
228
+ end
220
229
 
221
230
  ##Data over time
222
231
 
@@ -230,9 +239,9 @@ To install Axlsx, use the following command:
230
239
  sheet.add_chart(Axlsx::Bar3DChart) do |chart|
231
240
  chart.start_at "B7"
232
241
  chart.end_at "H27"
233
- chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
234
- end
235
- end
242
+ chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
243
+ end
244
+ end
236
245
 
237
246
  ##Generating A Line Chart
238
247
 
@@ -243,9 +252,9 @@ To install Axlsx, use the following command:
243
252
  chart.start_at 0, 2
244
253
  chart.end_at 10, 15
245
254
  chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
246
- chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
247
- end
248
- end
255
+ chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
256
+ end
257
+ end
249
258
 
250
259
  ##Auto Filter
251
260
 
@@ -256,7 +265,7 @@ To install Axlsx, use the following command:
256
265
  sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
257
266
  sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
258
267
  sheet.auto_filter = "A2:D5"
259
- end
268
+ end
260
269
 
261
270
  ##Specifying Column Widths
262
271
 
@@ -265,6 +274,12 @@ To install Axlsx, use the following command:
265
274
  sheet.column_widths nil, 3
266
275
  end
267
276
 
277
+ ##Specify Page Margins for printing
278
+ margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7}
279
+ wb.add_worksheet(:name => "print margins", :page_margins => margins) do |sheet|
280
+ sheet.add_row["this sheet uses customized page margins for printing"]
281
+ end
282
+
268
283
  ##Validate and Serialize
269
284
 
270
285
  p.validate.each { |e| puts e.message }
@@ -291,9 +306,19 @@ This gem is 100% documented with YARD, an exceptional documentation library. To
291
306
  #Specs
292
307
  ------
293
308
  This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory.
294
-
309
+
295
310
  #Changelog
296
311
  ---------
312
+ - ** March.5.12**: 1.0.18 release
313
+ https://github.com/randym/axlsx/compare/1.0.17...1.0.18
314
+ - bugfix custom borders are not properly applied when using styles.add_style
315
+ - interop worksheet names must be 31 characters or less or some versions of office complain about repairs
316
+ - added type support for :boolean and :date types cell values
317
+ - added support for fixed column widths
318
+ - added support for page_margins
319
+ - added << alias for add_row
320
+ - removed presetting of date1904 based on authoring platform. Now defaults to use 1900 epoch (date1904 = false)
321
+
297
322
  - ** February.14.12**: 1.0.17 release
298
323
  https://github.com/randym/axlsx/compare/1.0.16...1.0.17
299
324
  - Added in support for serializing to StringIO
@@ -308,8 +333,8 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
308
333
  - date1904 now automatically set in bsd and mac environments
309
334
  - removed whitespace/indentation from xml outputs
310
335
  - col_style now skips rows that do not contain cells at the column index
311
-
312
-
336
+
337
+
313
338
  Please see the {file:CHANGELOG.md} document for past release information.
314
339
 
315
340
  #Thanks!
@@ -320,8 +345,16 @@ Please see the {file:CHANGELOG.md} document for past release information.
320
345
 
321
346
  [ffmike](https://github.com/ffmike) - for knocking down an over restrictive i18n dependency, massive patience and great communication skills.
322
347
 
348
+ [JonathanTron](https://github.com/JonathanTron) - for giving the gem some style, and making sure it applies.
349
+
350
+ [JosephHalter](https://github.com/JosephHalter) - for making sure we arrive at the right time on the right date.
351
+
352
+ [noniq](https://github.com/noniq) - for keeping true to the gem's style, and making sure what we put on paper does not get marginalized.
353
+
354
+ [jurriaan](https://github.com/jurriaan) - for showing there is more than one way to skin a cat, and work with rows while you are at it.
355
+
323
356
  #Copyright and License
324
357
  ----------
325
358
 
326
- Axlsx &copy; 2011 by [Randy Morgan](mailto:digial.ipseity@gmail.com). Axlsx is
359
+ Axlsx &copy; 2011 by [Randy Morgan](mailto:digial.ipseity@gmail.com). Axlsx is
327
360
  licensed under the MIT license. Please see the {file:LICENSE} document for more information.
@@ -1,213 +1,226 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby -w -s
2
2
  # -*- coding: utf-8 -*-
3
- require 'axlsx.rb'
3
+ require 'axlsx.rb'
4
4
 
5
- p = Axlsx::Package.new
6
- wb = p.workbook
5
+ p = Axlsx::Package.new
6
+ wb = p.workbook
7
7
 
8
8
  #A Simple Workbook
9
9
 
10
- wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
11
- sheet.add_row ["First Column", "Second", "Third"]
12
- sheet.add_row [1, 2, 3]
13
- end
10
+ wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
11
+ sheet.add_row ["First Column", "Second", "Third"]
12
+ sheet.add_row [1, 2, 3]
13
+ end
14
14
 
15
15
  #Using Custom Styles
16
16
 
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
24
- end
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
24
+ end
25
25
 
26
26
  ##Using Custom Formatting and date1904
27
- require 'date'
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 [Date::strptime('2012-01-19','%Y-%m-%d'), 0.2, 32], :style => [date, percent, padded]
36
- end
37
- end
27
+ require 'date'
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 # Use the 1904 date system (Used by Excel for Mac < 2011)
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 [Date::strptime('2012-01-19','%Y-%m-%d'), 0.2, 32], :style => [date, percent, padded]
36
+ end
37
+ end
38
38
 
39
39
  ##Add an Image
40
40
 
41
- wb.add_worksheet(:name => "Images") do |sheet|
42
- img = File.expand_path('examples/image1.jpeg')
43
- sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
44
- image.width=720
45
- image.height=666
46
- image.start_at 2, 2
47
- end
48
- end
41
+ wb.add_worksheet(:name => "Images") do |sheet|
42
+ img = File.expand_path('examples/image1.jpeg')
43
+ sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
44
+ image.width=720
45
+ image.height=666
46
+ image.start_at 2, 2
47
+ end
48
+ end
49
49
 
50
50
  ##Add an Image with a hyperlink
51
51
 
52
- wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
53
- img = File.expand_path('examples/image1.jpeg')
54
- sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
55
- image.width=720
56
- image.height=666
57
- image.hyperlink.tooltip = "Labeled Link"
58
- image.start_at 2, 2
59
- end
60
- end
52
+ wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
53
+ img = File.expand_path('examples/image1.jpeg')
54
+ sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
55
+ image.width=720
56
+ image.height=666
57
+ image.hyperlink.tooltip = "Labeled Link"
58
+ image.start_at 2, 2
59
+ end
60
+ end
61
61
 
62
62
  ##Asian Language Support
63
63
 
64
- wb.add_worksheet(:name => "Unicode Support") do |sheet|
65
- sheet.add_row ["日本語"]
66
- sheet.add_row ["华语/華語"]
67
- sheet.add_row ["한국어/조선말"]
68
- end
64
+ wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
65
+ sheet.add_row ["日本語"]
66
+ sheet.add_row ["华语/華語"]
67
+ sheet.add_row ["한국어/조선말"]
68
+ end
69
69
 
70
70
  ##Styling Columns
71
71
 
72
- wb.styles do |s|
73
- percent = s.add_style :num_fmt => 9
74
- wb.add_worksheet(:name => "Styling Columns") do |sheet|
75
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
76
- sheet.add_row [1, 2, 0.3, 4]
77
- sheet.add_row [1, 2, 0.2, 4]
78
- sheet.add_row [1, 2, 0.1, 4]
79
- sheet.col_style 2, percent, :row_offset => 1
80
- end
81
- end
72
+ wb.styles do |s|
73
+ percent = s.add_style :num_fmt => 9
74
+ wb.add_worksheet(:name => "Styling Columns") do |sheet|
75
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
76
+ sheet.add_row [1, 2, 0.3, 4]
77
+ sheet.add_row [1, 2, 0.2, 4]
78
+ sheet.add_row [1, 2, 0.1, 4]
79
+ sheet.col_style 2, percent, :row_offset => 1
80
+ end
81
+ end
82
82
 
83
83
  ##Styling Rows
84
84
 
85
- wb.styles do |s|
86
- head = s.add_style :bg_color => "00", :fg_color => "FF"
87
- percent = s.add_style :num_fmt => 9
88
- wb.add_worksheet(:name => "Styling Rows") do |sheet|
89
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
90
- sheet.add_row [1, 2, 0.3, 4]
91
- sheet.add_row [1, 2, 0.2, 4]
92
- sheet.add_row [1, 2, 0.1, 4]
93
- sheet.col_style 2, percent, :row_offset => 1
94
- sheet.row_style 0, head
95
- end
96
- end
85
+ wb.styles do |s|
86
+ head = s.add_style :bg_color => "00", :fg_color => "FF"
87
+ percent = s.add_style :num_fmt => 9
88
+ wb.add_worksheet(:name => "Styling Rows") do |sheet|
89
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
90
+ sheet.add_row [1, 2, 0.3, 4]
91
+ sheet.add_row [1, 2, 0.2, 4]
92
+ sheet.add_row [1, 2, 0.1, 4]
93
+ sheet.col_style 2, percent, :row_offset => 1
94
+ sheet.row_style 0, head
95
+ end
96
+ end
97
97
 
98
98
  ##Styling Cell Overrides
99
99
 
100
- wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
101
- # cell level style overides when adding cells
102
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
103
- sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
104
- # cell level style overrides via sheet range
105
- sheet["A1:D1"].each { |c| c.color = "FF0000"}
106
- sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
107
- end
100
+ wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
101
+ # cell level style overides when adding cells
102
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
103
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
104
+ # cell level style overrides via sheet range
105
+ sheet["A1:D1"].each { |c| c.color = "FF0000"}
106
+ sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
107
+ end
108
108
 
109
109
  ##Using formula
110
110
 
111
- wb.add_worksheet(:name => "Using Formulas") do |sheet|
112
- sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
113
- sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
114
- end
111
+ wb.add_worksheet(:name => "Using Formulas") do |sheet|
112
+ sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
113
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
114
+ end
115
+
116
+ ##Automatic cell types
117
+
118
+ wb.add_worksheet(:name => "Automatic cell types") do |sheet|
119
+ sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
120
+ sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1]
121
+ end
115
122
 
116
123
  ##Merging Cells.
117
124
 
118
- wb.add_worksheet(:name => 'Merging Cells') do |sheet|
119
- # cell level style overides when adding cells
120
- sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
121
- sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
122
- sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
123
- sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
124
- sheet.merge_cells("A4:C4")
125
- sheet["A1:D1"].each { |c| c.color = "FF0000"}
126
- sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
127
- end
125
+ wb.add_worksheet(:name => 'Merging Cells') do |sheet|
126
+ # cell level style overides when adding cells
127
+ sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
128
+ sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
129
+ sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
130
+ sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
131
+ sheet.merge_cells("A4:C4")
132
+ sheet["A1:D1"].each { |c| c.color = "FF0000"}
133
+ sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
134
+ end
128
135
 
129
136
  ##Generating A Bar Chart
130
137
 
131
- wb.add_worksheet(:name => "Bar Chart") do |sheet|
132
- sheet.add_row ["A Simple Bar Chart"]
133
- sheet.add_row ["First", "Second", "Third"]
134
- sheet.add_row [1, 2, 3]
135
- sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
136
- chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
137
- end
138
- end
138
+ wb.add_worksheet(:name => "Bar Chart") do |sheet|
139
+ sheet.add_row ["A Simple Bar Chart"]
140
+ sheet.add_row ["First", "Second", "Third"]
141
+ sheet.add_row [1, 2, 3]
142
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
143
+ chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
144
+ end
145
+ end
139
146
 
140
147
  ##Generating A Pie Chart
141
148
 
142
- wb.add_worksheet(:name => "Pie Chart") do |sheet|
143
- sheet.add_row ["First", "Second", "Third", "Fourth"]
144
- sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
145
- sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
146
- chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
147
- end
148
- end
149
+ wb.add_worksheet(:name => "Pie Chart") do |sheet|
150
+ sheet.add_row ["First", "Second", "Third", "Fourth"]
151
+ sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
152
+ sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
153
+ chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
154
+ end
155
+ end
149
156
 
150
157
  ##Data over time
151
158
 
152
- wb.add_worksheet(:name=>'Charting Dates') do |sheet|
153
- # cell level style overides when adding cells
154
- sheet.add_row ['Date', 'Value'], :sz => 16
155
- sheet.add_row [Time.now - (7*60*60*24), 3]
156
- sheet.add_row [Time.now - (6*60*60*24), 7]
157
- sheet.add_row [Time.now - (5*60*60*24), 18]
158
- sheet.add_row [Time.now - (4*60*60*24), 1]
159
- sheet.add_chart(Axlsx::Bar3DChart) do |chart|
160
- chart.start_at "B7"
161
- chart.end_at "H27"
162
- chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
163
- end
164
- end
159
+ wb.add_worksheet(:name=>'Charting Dates') do |sheet|
160
+ # cell level style overides when adding cells
161
+ sheet.add_row ['Date', 'Value'], :sz => 16
162
+ sheet.add_row [Time.now - (7*60*60*24), 3]
163
+ sheet.add_row [Time.now - (6*60*60*24), 7]
164
+ sheet.add_row [Time.now - (5*60*60*24), 18]
165
+ sheet.add_row [Time.now - (4*60*60*24), 1]
166
+ sheet.add_chart(Axlsx::Bar3DChart) do |chart|
167
+ chart.start_at "B7"
168
+ chart.end_at "H27"
169
+ chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
170
+ end
171
+ end
165
172
 
166
173
  ##Generating A Line Chart
167
174
 
168
- wb.add_worksheet(:name => "Line Chart") do |sheet|
169
- sheet.add_row ["First", 1, 5, 7, 9]
170
- sheet.add_row ["Second", 5, 2, 14, 9]
171
- sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart|
172
- chart.start_at 0, 2
173
- chart.end_at 10, 15
174
- chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
175
- chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
176
- end
177
- end
175
+ wb.add_worksheet(:name => "Line Chart") do |sheet|
176
+ sheet.add_row ["First", 1, 5, 7, 9]
177
+ sheet.add_row ["Second", 5, 2, 14, 9]
178
+ sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart|
179
+ chart.start_at 0, 2
180
+ chart.end_at 10, 15
181
+ chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
182
+ chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
183
+ end
184
+ end
178
185
 
179
186
  ##Auto Filter
180
187
 
181
- wb.add_worksheet(:name => "Auto Filter") do |sheet|
182
- sheet.add_row ["Build Matrix"]
183
- sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
184
- sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
185
- sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
186
- sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
187
- sheet.auto_filter = "A2:D5"
188
- end
188
+ wb.add_worksheet(:name => "Auto Filter") do |sheet|
189
+ sheet.add_row ["Build Matrix"]
190
+ sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
191
+ sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
192
+ sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
193
+ sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
194
+ sheet.auto_filter = "A2:D5"
195
+ end
189
196
 
190
197
  ##Specifying Column Widths
191
198
 
192
- wb.add_worksheet(:name => "custom column widths") do |sheet|
193
- sheet.add_row ["I use autowidth and am very wide", "I use a custom width and am narrow"]
194
- sheet.column_widths nil, 3
195
- end
199
+ wb.add_worksheet(:name => "custom column widths") do |sheet|
200
+ sheet.add_row ["I use autowidth and am very wide", "I use a custom width and am narrow"]
201
+ sheet.column_widths nil, 3
202
+ end
203
+
204
+ ##Specify Page Margins for printing
205
+ margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7}
206
+ wb.add_worksheet(:name => "print margins", :page_margins => margins) do |sheet|
207
+ sheet.add_row ["this sheet uses customized page margins for printing"]
208
+ end
196
209
 
197
210
  ##Validate and Serialize
198
211
 
199
- p.validate.each { |e| puts e.message }
200
- p.serialize("example.xlsx")
212
+ p.validate.each { |e| puts e.message }
213
+ p.serialize("example.xlsx")
201
214
 
202
- s = p.to_stream()
203
- File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
215
+ s = p.to_stream()
216
+ File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
204
217
 
205
218
 
206
219
  ##Using Shared Strings
220
+ p.use_shared_strings = true
221
+ p.serialize("shared_strings_example.xlsx")
222
+
207
223
 
208
- p.use_shared_strings = true
209
- p.serialize("shared_strings_example.xlsx")
210
224
 
211
225
 
212
-
213
226