axlsx 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +21 -0
- data/LICENSE +1 -1
- data/README.md +38 -415
- data/examples/#extractive.csv# +0 -0
- data/examples/#extractive.rb# +45 -0
- data/examples/chart_colors.rb +73 -0
- data/examples/chart_colors.rb~ +0 -0
- data/examples/chart_colors.xlsx +0 -0
- data/examples/colored_series_data.xlsx +0 -0
- data/examples/conditional_formatting/getting_barred.xlsx +0 -0
- data/examples/example.rb +174 -113
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.csv +1 -0
- data/examples/extractive.csv~ +1 -0
- data/examples/extractive.rb +42 -0
- data/examples/extractive.rb~ +3 -0
- data/examples/extractive.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/stack.rb +21 -0
- data/examples/stack.rb~ +27 -0
- data/examples/stack.xlsx +0 -0
- data/examples/~$chart_colors.xlsx +0 -0
- data/examples/~$extractive.xlsx +0 -0
- data/lib/axlsx/drawing/ax_data_source.rb +25 -0
- data/lib/axlsx/drawing/ax_data_source.rb~ +55 -0
- data/lib/axlsx/drawing/axis.rb +12 -3
- data/lib/axlsx/drawing/bar_series.rb +23 -6
- data/lib/axlsx/drawing/cat_axis.rb +24 -0
- data/lib/axlsx/drawing/chart.rb +7 -5
- data/lib/axlsx/drawing/data_source.rb~ +51 -0
- data/lib/axlsx/drawing/drawing.rb +8 -4
- data/lib/axlsx/drawing/line_series.rb +20 -4
- data/lib/axlsx/drawing/num_data.rb +52 -0
- data/lib/axlsx/drawing/num_data.rb~ +51 -0
- data/lib/axlsx/drawing/num_data_source.rb +58 -0
- data/lib/axlsx/drawing/num_data_source.rb~ +54 -0
- data/lib/axlsx/drawing/num_val.rb +32 -0
- data/lib/axlsx/drawing/num_val.rb~ +40 -0
- data/lib/axlsx/drawing/pie_series.rb +18 -4
- data/lib/axlsx/drawing/ref.rb~ +41 -0
- data/lib/axlsx/drawing/scatter_series.rb +28 -2
- data/lib/axlsx/drawing/ser_axis.rb +1 -1
- data/lib/axlsx/drawing/series.rb +1 -1
- data/lib/axlsx/drawing/str_data.rb +42 -0
- data/lib/axlsx/drawing/str_data.rb~ +58 -0
- data/lib/axlsx/drawing/str_val.rb +33 -0
- data/lib/axlsx/drawing/str_val.rb~ +35 -0
- data/lib/axlsx/drawing/view_3D.rb +6 -3
- data/lib/axlsx/util/validators.rb +1 -1
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/worksheet/col.rb +2 -1
- data/lib/axlsx/workbook/worksheet/row.rb +44 -5
- data/lib/axlsx/workbook/worksheet/table.rb +1 -1
- data/test/drawing/tc_bar_series.rb +18 -13
- data/test/drawing/tc_cat_axis_data.rb +23 -13
- data/test/drawing/tc_chart.rb +0 -2
- data/test/drawing/tc_data_source.rb +17 -0
- data/test/drawing/tc_data_source.rb~ +30 -0
- data/test/drawing/tc_line_series.rb +3 -9
- data/test/drawing/tc_named_axis_data.rb +27 -0
- data/test/drawing/tc_num_data.rb +27 -0
- data/test/drawing/tc_num_data.rb~ +35 -0
- data/test/drawing/tc_num_val.rb +29 -0
- data/test/drawing/tc_num_val.rb~ +29 -0
- data/test/drawing/tc_pie_series.rb +4 -11
- data/test/drawing/tc_scatter_series.rb +6 -5
- data/test/drawing/tc_str_data.rb +18 -0
- data/test/drawing/tc_str_data.rb~ +30 -0
- data/test/drawing/tc_str_val.rb +21 -0
- data/test/drawing/tc_str_val.rb~ +26 -0
- data/test/drawing/tc_two_cell_anchor.rb +1 -1
- data/test/workbook/worksheet/tc_row.rb +6 -0
- metadata +65 -13
- data/lib/axlsx/drawing/cat_axis_data.rb +0 -34
- data/lib/axlsx/drawing/named_axis_data.rb +0 -36
- data/lib/axlsx/drawing/val_axis_data.rb +0 -27
- data/test/drawing/tc_val_axis_data.rb +0 -17
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
|
+
- ** April.18.12**: 1.1.1 release
|
4
|
+
- bugfix for autowidth calculations across multiple rows
|
5
|
+
- bugfix for dimension calculations with nil cells.
|
6
|
+
- REMOVED RMAGICK dependency WOOT!
|
7
|
+
- Update readme to show screenshot of gem output.
|
8
|
+
- Cleanup benchmark and add benchmark rake task
|
9
|
+
|
10
|
+
- ** April.3.12**: 1.1.0 release
|
11
|
+
- bugfix patch name_to_indecies to properly handle extended ranges.
|
12
|
+
- bugfix properly serialize chart title.
|
13
|
+
- lower rake minimum requirement for 1.8.7 apps that don't want to move on to 0.9 NOTE this will be reverted for 2.0.0 with workbook parsing!
|
14
|
+
- Added Fit to Page printing
|
15
|
+
- added support for turning off gridlines in charts.
|
16
|
+
- added support for turning off gridlines in worksheet.
|
17
|
+
- bugfix some apps like libraoffice require apply[x] attributes to be true. applyAlignment is now properly set.
|
18
|
+
- added option use_autowidth. When this is false RMagick will not be loaded or used in the stack. However it is still a requirement in the gem.
|
19
|
+
- added border style specification to styles#add_style. See the example in the readme.
|
20
|
+
- Support for tables added in - Note: Pre 2011 versions of Mac office do not support this feature and will warn.
|
21
|
+
- Support for splatter charts added
|
22
|
+
- Major (like 7x faster!) performance updates.
|
23
|
+
- Gem now supports for JRuby 1.6.7, as well as experimental support for Rubinius
|
3
24
|
|
4
25
|
- ** March.5.12**: 1.0.18 release
|
5
26
|
https://github.com/randym/axlsx/compare/1.0.17...1.0.18
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
16
16
|
|
17
17
|
**License**: MIT License
|
18
18
|
|
19
|
-
**Latest Version**: 1.1.
|
19
|
+
**Latest Version**: 1.1.4
|
20
20
|
|
21
21
|
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
|
22
22
|
|
@@ -24,7 +24,13 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
24
24
|
|
25
25
|
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
|
26
26
|
|
27
|
-
**Release Date**:
|
27
|
+
**Release Date**: May 3rd 2012
|
28
|
+
|
29
|
+
If you are working in rails, or with active record see:
|
30
|
+
http://github.com/randym/acts_as_xlsx
|
31
|
+
|
32
|
+
There are guides for using axlsx and acts_as_xlsx here:
|
33
|
+
[http://axlsx.blogspot.com](http://axlsx.blogspot.com)
|
28
34
|
|
29
35
|
Synopsis
|
30
36
|
--------
|
@@ -34,11 +40,6 @@ With Axlsx you can create excel worksheets with charts, images (with links), aut
|
|
34
40
|
|
35
41
|
![Screen 1](https://github.com/randym/axlsx/raw/master/examples/sample.png)
|
36
42
|
|
37
|
-
If you are working in rails, or with active record see:
|
38
|
-
http://github.com/randym/acts_as_xlsx
|
39
|
-
|
40
|
-
There are guides for using axlsx and acts_as_xlsx here:
|
41
|
-
[http://axlsx.blogspot.com](http://axlsx.blogspot.com)
|
42
43
|
|
43
44
|
|
44
45
|
Feature List
|
@@ -46,7 +47,7 @@ Feature List
|
|
46
47
|
|
47
48
|
**1. Author xlsx documents: Axlsx is made to let you easily and quickly generate professional xlsx based reports that can be validated before serialization.
|
48
49
|
|
49
|
-
**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.
|
50
|
+
**2. Generate 3D Pie, Line, Scatter 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. Customize gridlines, label rotation and series colors as well.
|
50
51
|
|
51
52
|
**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.
|
52
53
|
|
@@ -64,15 +65,15 @@ Feature List
|
|
64
65
|
|
65
66
|
**10. Support for formulas
|
66
67
|
|
67
|
-
**11. Support for cell merging
|
68
|
+
**11. Support for cell merging as well as column and row outline
|
68
69
|
|
69
|
-
**12. Auto filtering tables with worksheet.auto_filter
|
70
|
+
**12. Auto filtering tables with worksheet.auto_filter as well as support for Tables
|
70
71
|
|
71
72
|
**13. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).
|
72
73
|
|
73
74
|
**14. Output to file or StringIO
|
74
75
|
|
75
|
-
**15. Support for page margins
|
76
|
+
**15. Support for page margins and print options
|
76
77
|
|
77
78
|
Installing
|
78
79
|
----------
|
@@ -81,430 +82,52 @@ To install Axlsx, use the following command:
|
|
81
82
|
|
82
83
|
$ gem install axlsx
|
83
84
|
|
84
|
-
#
|
85
|
+
#Examples
|
85
86
|
------
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
#A Simple Workbook
|
95
|
-
|
96
|
-
```ruby
|
97
|
-
wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
|
98
|
-
sheet.add_row ["First Column", "Second", "Third"]
|
99
|
-
sheet.add_row [1, 2, 3]
|
100
|
-
end
|
101
|
-
```
|
102
|
-
|
103
|
-
#Using Custom Styles
|
104
|
-
|
105
|
-
```ruby
|
106
|
-
wb.styles do |s|
|
107
|
-
black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
|
108
|
-
blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
|
109
|
-
wb.add_worksheet(:name => "Custom Styles") do |sheet|
|
110
|
-
sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
|
111
|
-
sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
|
112
|
-
end
|
113
|
-
end
|
114
|
-
```
|
115
|
-
|
116
|
-
#Using Custom Border Styles
|
117
|
-
|
118
|
-
```ruby
|
119
|
-
wb.styles do |s|
|
120
|
-
red_border = s.add_style :border => { :style => :thin, :color =>"FFFF0000" }
|
121
|
-
blue_border = s.add_style :border => { :style => :thin, :color =>"FF0000FF" }
|
122
|
-
|
123
|
-
wb.add_worksheet(:name => "Custom Borders") do |sheet|
|
124
|
-
sheet.add_row ["wrap", "me", "Up in Red"], :style => red_border
|
125
|
-
sheet.add_row [1, 2, 3], :style => blue_border
|
126
|
-
end
|
127
|
-
end
|
128
|
-
```
|
129
|
-
|
130
|
-
|
131
|
-
##Using Custom Formatting and date1904
|
132
|
-
|
133
|
-
```ruby
|
134
|
-
require 'date'
|
135
|
-
wb.styles do |s|
|
136
|
-
date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
|
137
|
-
padded = s.add_style(:format_code => "00#", :border => Axlsx::STYLE_THIN_BORDER)
|
138
|
-
percent = s.add_style(:format_code => "0000%", :border => Axlsx::STYLE_THIN_BORDER)
|
139
|
-
# wb.date1904 = true # Use the 1904 date system (Used by Excel for Mac < 2011)
|
140
|
-
wb.add_worksheet(:name => "Formatting Data") do |sheet|
|
141
|
-
sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
|
142
|
-
sheet.add_row [Date::strptime('2012-01-19','%Y-%m-%d'), 0.2, 32], :style => [date, percent, padded]
|
143
|
-
end
|
144
|
-
end
|
145
|
-
```
|
146
|
-
|
147
|
-
|
148
|
-
##Add an Image
|
149
|
-
|
150
|
-
```ruby
|
151
|
-
wb.add_worksheet(:name => "Images") do |sheet|
|
152
|
-
img = File.expand_path('../image1.jpeg', __FILE__)
|
153
|
-
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
|
154
|
-
image.width=720
|
155
|
-
image.height=666
|
156
|
-
image.start_at 2, 2
|
157
|
-
end
|
158
|
-
end
|
159
|
-
```
|
160
|
-
|
161
|
-
##Add an Image with a hyperlink
|
162
|
-
|
163
|
-
```ruby
|
164
|
-
wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
|
165
|
-
img = File.expand_path('../image1.jpeg', __FILE__)
|
166
|
-
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
|
167
|
-
image.width=720
|
168
|
-
image.height=666
|
169
|
-
image.hyperlink.tooltip = "Labeled Link"
|
170
|
-
image.start_at 2, 2
|
171
|
-
end
|
172
|
-
end
|
173
|
-
```
|
174
|
-
|
175
|
-
##Asian Language Support
|
176
|
-
|
177
|
-
```ruby
|
178
|
-
wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
|
179
|
-
sheet.add_row ["日本語"]
|
180
|
-
sheet.add_row ["华语/華語"]
|
181
|
-
sheet.add_row ["한국어/조선말"]
|
182
|
-
end
|
183
|
-
```
|
184
|
-
|
185
|
-
##Styling Columns
|
186
|
-
|
187
|
-
```ruby
|
188
|
-
wb.styles do |s|
|
189
|
-
percent = s.add_style :num_fmt => 9
|
190
|
-
wb.add_worksheet(:name => "Styling Columns") do |sheet|
|
191
|
-
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
192
|
-
sheet.add_row [1, 2, 0.3, 4]
|
193
|
-
sheet.add_row [1, 2, 0.2, 4]
|
194
|
-
sheet.add_row [1, 2, 0.1, 4]
|
195
|
-
sheet.col_style 2, percent, :row_offset => 1
|
196
|
-
end
|
197
|
-
end
|
198
|
-
```
|
199
|
-
|
200
|
-
##Hiding Columns
|
201
|
-
|
202
|
-
```ruby
|
203
|
-
wb.styles do |s|
|
204
|
-
percent = s.add_style :num_fmt => 9
|
205
|
-
wb.add_worksheet(:name => "Hidden Column") do |sheet|
|
206
|
-
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
207
|
-
sheet.add_row [1, 2, 0.3, 4]
|
208
|
-
sheet.add_row [1, 2, 0.2, 4]
|
209
|
-
sheet.add_row [1, 2, 0.1, 4]
|
210
|
-
sheet.col_style 2, percent, :row_offset => 1
|
211
|
-
sheet.column_info[1].hidden = true
|
212
|
-
end
|
213
|
-
end
|
214
|
-
```
|
215
|
-
|
216
|
-
##Styling Rows
|
217
|
-
|
218
|
-
```ruby
|
219
|
-
wb.styles do |s|
|
220
|
-
head = s.add_style :bg_color => "00", :fg_color => "FF"
|
221
|
-
percent = s.add_style :num_fmt => 9
|
222
|
-
wb.add_worksheet(:name => "Styling Rows") do |sheet|
|
223
|
-
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
224
|
-
sheet.add_row [1, 2, 0.3, 4]
|
225
|
-
sheet.add_row [1, 2, 0.2, 4]
|
226
|
-
sheet.add_row [1, 2, 0.1, 4]
|
227
|
-
sheet.col_style 2, percent, :row_offset => 1
|
228
|
-
sheet.row_style 0, head
|
229
|
-
end
|
230
|
-
end
|
231
|
-
```
|
232
|
-
|
233
|
-
##Styling Cell Overrides
|
234
|
-
|
235
|
-
```ruby
|
236
|
-
wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
|
237
|
-
# cell level style overides when adding cells
|
238
|
-
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16
|
239
|
-
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
240
|
-
# cell level style overrides via sheet range
|
241
|
-
sheet["A1:D1"].each { |c| c.color = "FF0000"}
|
242
|
-
sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
|
243
|
-
end
|
244
|
-
```
|
245
|
-
|
246
|
-
##Using formula
|
247
|
-
|
248
|
-
```ruby
|
249
|
-
wb.add_worksheet(:name => "Using Formulas") do |sheet|
|
250
|
-
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
251
|
-
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
252
|
-
end
|
253
|
-
```
|
254
|
-
|
255
|
-
##Automatic cell types
|
256
|
-
|
257
|
-
```ruby
|
258
|
-
wb.add_worksheet(:name => "Automatic cell types") do |sheet|
|
259
|
-
sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
|
260
|
-
sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1]
|
261
|
-
end
|
262
|
-
```
|
263
|
-
|
264
|
-
##Merging Cells.
|
265
|
-
|
266
|
-
```ruby
|
267
|
-
wb.add_worksheet(:name => 'Merging Cells') do |sheet|
|
268
|
-
# cell level style overides when adding cells
|
269
|
-
sheet.add_row ["col 1", "col 2", "col 3", "col 4"], :sz => 16
|
270
|
-
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
271
|
-
sheet.add_row [2, 3, 4, "=SUM(A3:C3)"]
|
272
|
-
sheet.add_row ["total", "", "", "=SUM(D2:D3)"]
|
273
|
-
sheet.merge_cells("A4:C4")
|
274
|
-
sheet["A1:D1"].each { |c| c.color = "FF0000"}
|
275
|
-
sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
|
276
|
-
end
|
277
|
-
```
|
278
|
-
|
279
|
-
##Generating A Bar Chart
|
280
|
-
|
281
|
-
```ruby
|
282
|
-
wb.add_worksheet(:name => "Bar Chart") do |sheet|
|
283
|
-
sheet.add_row ["A Simple Bar Chart"]
|
284
|
-
sheet.add_row ["First", "Second", "Third"]
|
285
|
-
sheet.add_row [1, 2, 3]
|
286
|
-
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
|
287
|
-
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
288
|
-
chart.valAxis.label_rotation = -45
|
289
|
-
chart.catAxis.label_rotation = 45
|
290
|
-
end
|
291
|
-
end
|
292
|
-
```
|
293
|
-
|
294
|
-
##Hide Gridlines in chart
|
295
|
-
|
296
|
-
```ruby
|
297
|
-
wb.add_worksheet(:name => "Chart With No Gridlines") do |sheet|
|
298
|
-
sheet.add_row ["A Simple Bar Chart"]
|
299
|
-
sheet.add_row ["First", "Second", "Third"]
|
300
|
-
sheet.add_row [1, 2, 3]
|
301
|
-
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A4", :end_at => "F17") do |chart|
|
302
|
-
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
303
|
-
chart.valAxis.gridlines = false
|
304
|
-
chart.catAxis.gridlines = false
|
305
|
-
end
|
306
|
-
end
|
307
|
-
```
|
308
|
-
|
309
|
-
##Generating A Pie Chart
|
310
|
-
|
311
|
-
```ruby
|
312
|
-
wb.add_worksheet(:name => "Pie Chart") do |sheet|
|
313
|
-
sheet.add_row ["First", "Second", "Third", "Fourth"]
|
314
|
-
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
|
315
|
-
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
|
316
|
-
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
|
317
|
-
end
|
318
|
-
end
|
319
|
-
```
|
320
|
-
|
321
|
-
##Data over time
|
322
|
-
|
323
|
-
```ruby
|
324
|
-
wb.add_worksheet(:name=>'Charting Dates') do |sheet|
|
325
|
-
# cell level style overides when adding cells
|
326
|
-
sheet.add_row ['Date', 'Value'], :sz => 16
|
327
|
-
sheet.add_row [Time.now - (7*60*60*24), 3]
|
328
|
-
sheet.add_row [Time.now - (6*60*60*24), 7]
|
329
|
-
sheet.add_row [Time.now - (5*60*60*24), 18]
|
330
|
-
sheet.add_row [Time.now - (4*60*60*24), 1]
|
331
|
-
sheet.add_chart(Axlsx::Bar3DChart) do |chart|
|
332
|
-
chart.start_at "B7"
|
333
|
-
chart.end_at "H27"
|
334
|
-
chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
|
335
|
-
end
|
336
|
-
end
|
337
|
-
```
|
338
|
-
|
339
|
-
##Generating A Line Chart
|
340
|
-
|
341
|
-
```ruby
|
342
|
-
wb.add_worksheet(:name => "Line Chart") do |sheet|
|
343
|
-
sheet.add_row ["First", 1, 5, 7, 9]
|
344
|
-
sheet.add_row ["Second", 5, 2, 14, 9]
|
345
|
-
sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 20) do |chart|
|
346
|
-
chart.start_at 0, 2
|
347
|
-
chart.end_at 10, 15
|
348
|
-
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"]
|
349
|
-
chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"]
|
350
|
-
end
|
351
|
-
end
|
352
|
-
```
|
353
|
-
|
354
|
-
##Generating A Scatter Chart
|
355
|
-
|
356
|
-
```ruby
|
357
|
-
wb.add_worksheet(:name => "Scatter Chart") do |sheet|
|
358
|
-
sheet.add_row ["First", 1, 5, 7, 9]
|
359
|
-
sheet.add_row ["", 1, 25, 49, 81]
|
360
|
-
sheet.add_row ["Second", 5, 2, 14, 9]
|
361
|
-
sheet.add_row ["", 5, 10, 15, 20]
|
362
|
-
sheet.add_chart(Axlsx::ScatterChart, :title => "example 7: Scatter Chart") do |chart|
|
363
|
-
chart.start_at 0, 4
|
364
|
-
chart.end_at 10, 19
|
365
|
-
chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :title => sheet["A1"]
|
366
|
-
chart.add_series :xData => sheet["B3:E3"], :yData => sheet["B4:E4"], :title => sheet["A3"]
|
367
|
-
end
|
368
|
-
end
|
369
|
-
```
|
370
|
-
|
371
|
-
##Auto Filter
|
372
|
-
|
373
|
-
```ruby
|
374
|
-
wb.add_worksheet(:name => "Auto Filter") do |sheet|
|
375
|
-
sheet.add_row ["Build Matrix"]
|
376
|
-
sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
|
377
|
-
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
|
378
|
-
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
379
|
-
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
380
|
-
sheet.auto_filter = "A2:D5"
|
381
|
-
end
|
382
|
-
```
|
383
|
-
|
384
|
-
##Tables
|
385
|
-
|
386
|
-
```ruby
|
387
|
-
wb.add_worksheet(:name => "Table") do |sheet|
|
388
|
-
sheet.add_row ["Build Matrix"]
|
389
|
-
sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
|
390
|
-
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
|
391
|
-
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
392
|
-
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
393
|
-
sheet.add_table "A2:D5", :name => 'Build Matrix'
|
394
|
-
end
|
395
|
-
```
|
396
|
-
|
397
|
-
##Specifying Column Widths
|
398
|
-
|
399
|
-
```ruby
|
400
|
-
wb.add_worksheet(:name => "custom column widths") do |sheet|
|
401
|
-
sheet.add_row ["I use autowidth and am very wide", "I use a custom width and am narrow"]
|
402
|
-
sheet.add_row ['abcdefg', 'This is a very long text and should flow into the right cell', nil, 'xxx' ]
|
403
|
-
sheet.column_widths nil, 3, 5, nil
|
404
|
-
end
|
405
|
-
```
|
406
|
-
|
407
|
-
##Fit to page printing
|
408
|
-
|
409
|
-
```ruby
|
410
|
-
wb.add_worksheet(:name => "fit to page") do |sheet|
|
411
|
-
sheet.add_row ['this all goes on one page']
|
412
|
-
sheet.fit_to_page = true
|
413
|
-
end
|
414
|
-
```
|
415
|
-
|
416
|
-
##Hide Gridlines in worksheet
|
417
|
-
|
418
|
-
```ruby
|
419
|
-
wb.add_worksheet(:name => "No Gridlines") do |sheet|
|
420
|
-
sheet.add_row ["This", "Sheet", "Hides", "Gridlines"]
|
421
|
-
sheet.show_gridlines = false
|
422
|
-
end
|
423
|
-
```
|
424
|
-
|
425
|
-
##Specify Page Margins for printing
|
426
|
-
|
427
|
-
```ruby
|
428
|
-
margins = {:left => 3, :right => 3, :top => 1.2, :bottom => 1.2, :header => 0.7, :footer => 0.7}
|
429
|
-
wb.add_worksheet(:name => "print margins", :page_margins => margins) do |sheet|
|
430
|
-
sheet.add_row ["this sheet uses customized page margins for printing"]
|
431
|
-
end
|
432
|
-
```
|
433
|
-
|
434
|
-
##Validate and Serialize
|
435
|
-
|
436
|
-
```ruby
|
437
|
-
p.serialize("example.xlsx")
|
438
|
-
|
439
|
-
s = p.to_stream()
|
440
|
-
File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) }
|
441
|
-
```
|
442
|
-
|
443
|
-
##Using Shared Strings
|
444
|
-
|
445
|
-
```ruby
|
446
|
-
p.use_shared_strings = true
|
447
|
-
p.serialize("shared_strings_example.xlsx")
|
448
|
-
```
|
449
|
-
|
450
|
-
##Disabling Autowidth
|
451
|
-
|
452
|
-
```ruby
|
453
|
-
p = Axlsx::Package.new
|
454
|
-
p.use_autowidth = false
|
455
|
-
wb = p.workbook
|
456
|
-
wb.add_worksheet(:name => "Manual Widths") do | sheet |
|
457
|
-
sheet.add_row ['oh look! no autowidth']
|
458
|
-
end
|
459
|
-
p.validate.each { |e| puts e.message }
|
460
|
-
p.serialize("no-use_autowidth.xlsx")
|
461
|
-
```
|
88
|
+
The example listing is getting overly large to maintain here.
|
89
|
+
If you are using Yard, you will be able to see the examples inline below.
|
90
|
+
If not, please refer to the Please see the {file:examples/example.rb} file.
|
91
|
+
|
92
|
+
{include:file:examples/example.rb}
|
93
|
+
|
94
|
+
There is much, much more you can do with this gem. If you get stuck, grab me on IRC or submit an issue to Github. Chances are that it has already been implemented. If it hasn't - let's take a look at adding it in.
|
462
95
|
|
463
96
|
#Documentation
|
464
97
|
--------------
|
465
98
|
This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use:
|
466
99
|
|
467
|
-
|
468
|
-
|
469
|
-
yard server -g
|
470
|
-
|
100
|
+
gem install yard
|
101
|
+
|
102
|
+
yard server -g
|
103
|
+
|
471
104
|
#Specs
|
472
105
|
------
|
473
106
|
This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory.
|
474
107
|
|
475
108
|
#Change log
|
476
109
|
---------
|
477
|
-
- **
|
110
|
+
- ** May.3.12:**: 1.1.4 release
|
111
|
+
- MOAR examples
|
112
|
+
- added outline level for rows and columns
|
113
|
+
- rebuild of numeric and axis data sources for charts
|
114
|
+
- added delete to axis
|
115
|
+
- added tick and label mark skipping for cat axis in charts
|
116
|
+
- bugfix for table headers method
|
117
|
+
- sane(er) defaults for chart positioning
|
118
|
+
- bugfix in val_axis_data to properly serialize value axis data. Excel does not mind as it reads from the sheet, but nokogiri has a fit if the elements are empty.
|
119
|
+
- Added support for specifying the color of data series in charts.
|
120
|
+
- bugfix using add_cell on row mismanaged calls to update_column_info.
|
121
|
+
|
122
|
+
- ** April.25.12:**: 1.1.3 release
|
478
123
|
- Primarily because I am stupid.....Updates to readme to properly report version, add in missing docs and restructure example directory.
|
479
124
|
|
480
|
-
- ** April.25.12
|
125
|
+
- ** April.25.12:**: 1.1.2 release
|
481
126
|
- Conditional Formatting completely implemented.
|
482
127
|
- refactoring / documentation for Style#add_style
|
483
128
|
- added in label rotation for chart axis labels
|
484
129
|
- bugfix to properly assign style and type info to cells when only partial information is provided in the types/style option
|
485
130
|
|
486
|
-
- ** April.18.12**: 1.1.1 release
|
487
|
-
- bugfix for autowidth calculations across multiple rows
|
488
|
-
- bugfix for dimension calculations with nil cells.
|
489
|
-
- REMOVED RMAGICK dependency WOOT!
|
490
|
-
- Update readme to show screenshot of gem output.
|
491
|
-
- Cleanup benchmark and add benchmark rake task
|
492
|
-
|
493
|
-
- ** April.3.12**: 1.1.0 release
|
494
|
-
- bugfix patch name_to_indecies to properly handle extended ranges.
|
495
|
-
- bugfix properly serialize chart title.
|
496
|
-
- lower rake minimum requirement for 1.8.7 apps that don't want to move on to 0.9 NOTE this will be reverted for 2.0.0 with workbook parsing!
|
497
|
-
- Added Fit to Page printing
|
498
|
-
- added support for turning off gridlines in charts.
|
499
|
-
- added support for turning off gridlines in worksheet.
|
500
|
-
- bugfix some apps like libraoffice require apply[x] attributes to be true. applyAlignment is now properly set.
|
501
|
-
- added option use_autowidth. When this is false RMagick will not be loaded or used in the stack. However it is still a requirement in the gem.
|
502
|
-
- added border style specification to styles#add_style. See the example in the readme.
|
503
|
-
- Support for tables added in - Note: Pre 2011 versions of Mac office do not support this feature and will warn.
|
504
|
-
- Support for splatter charts added
|
505
|
-
- Major (like 7x faster!) performance updates.
|
506
|
-
- Gem now supports for JRuby 1.6.7, as well as experimental support for Rubinius
|
507
|
-
|
508
131
|
Please see the {file:CHANGELOG.md} document for past release information.
|
509
132
|
|
510
133
|
#Thanks!
|