axlsx 1.2.0 → 1.3.1
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/.yardopts +3 -2
- data/CHANGELOG.md +34 -1
- data/README.md +36 -30
- data/Rakefile +1 -1
- data/examples/auto_filter.rb +16 -0
- data/examples/auto_filter.xlsx +0 -0
- data/examples/basic_charts.rb +4 -0
- data/examples/example.rb +41 -13
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.xlsx +0 -0
- data/examples/hyperlinks.rb +23 -0
- data/examples/hyperlinks.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/page_setup.rb +11 -0
- data/examples/page_setup.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/skydrive/axlsx.csv +1 -0
- data/examples/skydrive/axlsx.xlsx +0 -0
- data/examples/skydrive/real_example.rb +8 -8
- data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
- data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
- data/examples/sprk2012/basics.rb +11 -0
- data/examples/sprk2012/basics.xlsx +0 -0
- data/examples/sprk2012/gravatar.jpeg +0 -0
- data/examples/sprk2012/hair_club.jpg +0 -0
- data/examples/sprk2012/images.rb +9 -0
- data/examples/sprk2012/images.xlsx +0 -0
- data/examples/sprk2012/line_chart.rb +56 -0
- data/examples/sprk2012/line_chart.xlsx +0 -0
- data/examples/sprk2012/sprk2012.key +0 -0
- data/examples/sprk2012/styles.rb +20 -0
- data/examples/sprk2012/styles.xlsx +0 -0
- data/examples/styles.rb +62 -0
- data/examples/styles.xlsx +0 -0
- data/lib/axlsx/doc_props/app.rb +3 -3
- data/lib/axlsx/drawing/axis.rb +1 -1
- data/lib/axlsx/drawing/view_3D.rb +1 -1
- data/lib/axlsx/package.rb +0 -1
- data/lib/axlsx/stylesheet/styles.rb +10 -1
- data/lib/axlsx/util/constants.rb +105 -4
- data/lib/axlsx/util/simple_typed_list.rb +3 -1
- data/lib/axlsx/util/validators.rb +26 -8
- data/lib/axlsx/version.rb +2 -2
- data/lib/axlsx/workbook/workbook.rb +6 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +102 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +253 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +10 -5
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +47 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +135 -7
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +49 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +87 -4
- data/lib/axlsx/workbook/worksheet/table.rb +8 -1
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +68 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +45 -7
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +101 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
- data/lib/axlsx.rb +8 -1
- data/test/stylesheet/tc_styles.rb +13 -0
- data/test/tc_package.rb +1 -0
- data/test/util/tc_validators.rb +8 -1
- data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
- data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
- data/test/workbook/worksheet/tc_cell.rb +23 -1
- data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
- data/test/workbook/worksheet/tc_page_setup.rb +6 -1
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
- data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
- data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +6 -1
- data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
- data/test/workbook/worksheet/tc_worksheet.rb +17 -3
- data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +64 -0
- metadata +59 -6
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
CHANGELOG
|
|
2
2
|
---------
|
|
3
|
+
- **August.27.12**: 1.2.2
|
|
4
|
+
- minor patch for auto-filters
|
|
5
|
+
- minor documentation improvements.
|
|
6
|
+
- **August.12.12**: 1.2.1
|
|
7
|
+
- Add support for hyperlinks in worksheets
|
|
8
|
+
- Fix example that was using old style cell merging with concact.
|
|
9
|
+
- Fix bug that occurs when calculating the font_size for cells that use a user specified style which does not define sz
|
|
10
|
+
- **August.5.12**: 1.2.0
|
|
11
|
+
- rebuilt worksheet serialization to clean up the code base a bit.
|
|
12
|
+
- added data labels for charts
|
|
13
|
+
- added table header printing for each sheet via defined_name. This
|
|
14
|
+
means that when you print your worksheet, the header rows show for every page
|
|
15
|
+
- **July.??.12**: 1.1.9 release
|
|
16
|
+
- lots of code clean up for worksheet
|
|
17
|
+
- added in data labels for pie charts, line charts and bar charts.
|
|
18
|
+
- bugfix chard with data in a sheet that has a space in the name are
|
|
19
|
+
now auto updating formula based values
|
|
20
|
+
- **July.14.12**: 1.1.8 release
|
|
21
|
+
- added html entity encoding for sheet names. This allows you to use
|
|
22
|
+
characters like '<' and '&' in your sheet names.
|
|
23
|
+
- new - first round google docs interoperability
|
|
24
|
+
- added filter to strip out control characters from cell data.
|
|
25
|
+
- added in interop requirements so that charts are properly exported
|
|
26
|
+
to PDF from Libra Office
|
|
27
|
+
- various readability improvements and work standardizing attribute
|
|
28
|
+
names to snake_case. Aliases are provided for backward compatiblity
|
|
29
|
+
- **June.11.12**: 1.1.7 release
|
|
30
|
+
- fix chart rendering issue when label offset is specified as a
|
|
31
|
+
percentage in serialization and ensure that formula are not stored
|
|
32
|
+
in value caches
|
|
33
|
+
- fix bug that causes repair warnings when using a text only title reference.
|
|
34
|
+
- Add title property to axis so you can lable the x/y/series axis for
|
|
35
|
+
charts.
|
|
36
|
+
- Add sheet views with panes
|
|
3
37
|
- **May.30.12**: 1.1.6 release
|
|
4
38
|
- data protection with passwords for sheets
|
|
5
39
|
- cell level input validators
|
|
@@ -10,7 +44,6 @@ CHANGELOG
|
|
|
10
44
|
- added ph (phonetics) and s (style) attributes for row.
|
|
11
45
|
- resolved all warnings generating from this gem.
|
|
12
46
|
- improved comment relationship management for multiple comments
|
|
13
|
-
|
|
14
47
|
- **May.13.12**: 1.1.5 release
|
|
15
48
|
- MOAR print options! You can now specify paper size, orientation,
|
|
16
49
|
fit to width, page margings and gridlines for printing.
|
data/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
Axlsx: Office Open XML Spreadsheet Generation
|
|
2
2
|
====================================
|
|
3
3
|
[](http://travis-ci.org/randym/axlsx/)
|
|
4
|
+
|
|
5
|
+
If you are using axlsx for comercial purposes, or just want to show your
|
|
6
|
+
appreciation for the gem, please don't hesitate to make a donation.
|
|
7
|
+
|
|
4
8
|
[](http://www.pledgie.com/campaigns/17814)
|
|
5
9
|
|
|
6
10
|
**IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
|
|
@@ -17,7 +21,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
|
17
21
|
|
|
18
22
|
**License**: MIT License
|
|
19
23
|
|
|
20
|
-
**Latest Version**: 1.
|
|
24
|
+
**Latest Version**: 1.3.1
|
|
21
25
|
|
|
22
26
|
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
|
|
23
27
|
|
|
@@ -25,7 +29,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
|
25
29
|
|
|
26
30
|
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
|
|
27
31
|
|
|
28
|
-
**Release Date**:
|
|
32
|
+
**Release Date**: September 30th 2012
|
|
29
33
|
|
|
30
34
|
If you are working in rails, or with active record see:
|
|
31
35
|
* http://github.com/randym/acts_as_xlsx
|
|
@@ -145,33 +149,19 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
|
145
149
|
|
|
146
150
|
#Change log
|
|
147
151
|
---------
|
|
148
|
-
- **
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
- new - first round google docs interoperability
|
|
162
|
-
- added filter to strip out control characters from cell data.
|
|
163
|
-
- added in interop requirements so that charts are properly exported
|
|
164
|
-
to PDF from Libra Office
|
|
165
|
-
- various readability improvements and work standardizing attribute
|
|
166
|
-
names to snake_case. Aliases are provided for backward compatiblity
|
|
167
|
-
- **June.11.12**: 1.1.7 release
|
|
168
|
-
- fix chart rendering issue when label offset is specified as a
|
|
169
|
-
percentage in serialization and ensure that formula are not stored
|
|
170
|
-
in value caches
|
|
171
|
-
- fix bug that causes repair warnings when using a text only title reference.
|
|
172
|
-
- Add title property to axis so you can lable the x/y/series axis for
|
|
173
|
-
charts.
|
|
174
|
-
- Add sheet views with panes
|
|
152
|
+
- **September.30.12**: 1.3.1
|
|
153
|
+
- Improved control character handling
|
|
154
|
+
- Added stored auto filter values and date grouping items
|
|
155
|
+
- Improved support for autowidth when custom styles are applied
|
|
156
|
+
- Added support for table style info that lets you take advantage of
|
|
157
|
+
all the predefined table styles.
|
|
158
|
+
- Improved style management for fonts so they merge undefined values
|
|
159
|
+
from the initial master.
|
|
160
|
+
- **September.8.12**: 1.2.3
|
|
161
|
+
- enhance exponential float/bigdecimal values rendering as strings intead
|
|
162
|
+
of 'numbers' in excel.
|
|
163
|
+
- added support for :none option on chart axis labels
|
|
164
|
+
- added support for paper_size option on worksheet.page_setup
|
|
175
165
|
|
|
176
166
|
Please see the {file:CHANGELOG.md} document for past release information.
|
|
177
167
|
|
|
@@ -193,7 +183,19 @@ related to themes, which axlsx does not implement at this time.
|
|
|
193
183
|
- border colors do not work
|
|
194
184
|
|
|
195
185
|
3. Numbers
|
|
196
|
-
- you must set 'use_shared_strings' to true
|
|
186
|
+
- you must set 'use_shared_strings' to true. This is most
|
|
187
|
+
conveniently done just before rendering by calling Package.use_shared_strings = true prior to serialization.
|
|
188
|
+
|
|
189
|
+
```ruby
|
|
190
|
+
p = Axlsx::Package.new
|
|
191
|
+
p.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
|
|
192
|
+
sheet.add_row ["First Column", "Second", "Third"]
|
|
193
|
+
sheet.add_row [1, 2, 3]
|
|
194
|
+
end
|
|
195
|
+
p.use_shared_strings = true
|
|
196
|
+
p.serialize('simple.xlsx')
|
|
197
|
+
```
|
|
198
|
+
|
|
197
199
|
- charts do not render
|
|
198
200
|
|
|
199
201
|
|
|
@@ -229,6 +231,10 @@ done without the help of the people below.
|
|
|
229
231
|
|
|
230
232
|
[straydogstudio](https://github.com/straydocstudio) - For making an AWESOME axlsx templating gem for rails.
|
|
231
233
|
|
|
234
|
+
[MitchellAJ](https://github.com/MitchellAJ) - For catching a bug in font_size calculations, finding some old code in an example and above all for reporting all of that brilliantly
|
|
235
|
+
|
|
236
|
+
[ebenoist](https://github.com/ebenoist) - For taking control of control characters and keeping what is between the lines, between the lines.
|
|
237
|
+
|
|
232
238
|
#Copyright and License
|
|
233
239
|
----------
|
|
234
240
|
|
data/Rakefile
CHANGED
|
@@ -11,7 +11,7 @@ end
|
|
|
11
11
|
task :gendoc do
|
|
12
12
|
#puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
|
|
13
13
|
system "yardoc"
|
|
14
|
-
system "yard stats --list-undoc"
|
|
14
|
+
#system "yard stats --list-undoc"
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
task :test do
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
5
|
+
require 'axlsx'
|
|
6
|
+
Axlsx::Package.new do |p|
|
|
7
|
+
p.workbook.add_worksheet(:name => "Table") do |sheet|
|
|
8
|
+
sheet.add_row ["Build Matrix"]
|
|
9
|
+
sheet.add_row ["Build", "Duration", "Finished", "Rvm"]
|
|
10
|
+
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
|
|
11
|
+
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
|
12
|
+
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
|
13
|
+
sheet.auto_filter = 'A2:D5'
|
|
14
|
+
sheet.auto_filter.add_column 3, :filters, :filter_items => ['1.9.2']
|
|
15
|
+
end
|
|
16
|
+
end.serialize('auto_filter.xlsx')
|
|
Binary file
|
data/examples/basic_charts.rb
CHANGED
|
@@ -24,6 +24,8 @@ end
|
|
|
24
24
|
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :title => 'bob'
|
|
25
25
|
chart.d_lbls.show_val = true
|
|
26
26
|
chart.d_lbls.show_cat_name = true
|
|
27
|
+
chart.catAxis.tick_lbl_pos = :none
|
|
28
|
+
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
@@ -38,6 +40,8 @@ end
|
|
|
38
40
|
chart.catAxis.label_rotation = 45
|
|
39
41
|
chart.d_lbls.d_lbl_pos = :outEnd
|
|
40
42
|
chart.d_lbls.show_val = true
|
|
43
|
+
|
|
44
|
+
chart.catAxis.tick_lbl_pos = :none
|
|
41
45
|
end
|
|
42
46
|
end
|
|
43
47
|
|
data/examples/example.rb
CHANGED
|
@@ -55,22 +55,22 @@ wb.add_worksheet(:name => "Cell Level Style Overrides") do |sheet|
|
|
|
55
55
|
sheet["A1:D1"].each { |c| c.color = "FF0000" }
|
|
56
56
|
sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
##```
|
|
59
59
|
|
|
60
60
|
##Using Custom Border Styles
|
|
61
61
|
|
|
62
62
|
#```ruby
|
|
63
63
|
#Axlsx defines a thin border style, but you can easily create and use your own.
|
|
64
64
|
wb.styles do |s|
|
|
65
|
-
red_border = s.add_style :border => { :style => :thick, :color =>"FFFF0000" }
|
|
66
|
-
blue_border = s.add_style :border => { :style => :thick, :color =>"FF0000FF"
|
|
65
|
+
red_border = s.add_style :border => { :style => :thick, :color =>"FFFF0000", :edges => [:left, :right] }
|
|
66
|
+
blue_border = s.add_style :border => { :style => :thick, :color =>"FF0000FF"}
|
|
67
67
|
|
|
68
68
|
wb.add_worksheet(:name => "Custom Borders") do |sheet|
|
|
69
69
|
sheet.add_row ["wrap", "me", "Up in Red"], :style => red_border
|
|
70
70
|
sheet.add_row [1, 2, 3], :style => blue_border
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
|
-
|
|
73
|
+
##```
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
##Styling Rows and Columns
|
|
@@ -101,7 +101,7 @@ wb.styles do |s|
|
|
|
101
101
|
sheet.rows[1].outlineLevel = 2
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
|
-
|
|
104
|
+
##```
|
|
105
105
|
|
|
106
106
|
|
|
107
107
|
##Specifying Column Widths
|
|
@@ -112,7 +112,7 @@ wb.add_worksheet(:name => "custom column widths") do |sheet|
|
|
|
112
112
|
sheet.add_row ['abcdefg', 'This is a very long text and should flow into the right cell', nil, 'xxx' ]
|
|
113
113
|
sheet.column_widths nil, 3, 5, nil
|
|
114
114
|
end
|
|
115
|
-
|
|
115
|
+
##```
|
|
116
116
|
|
|
117
117
|
##Merging Cells.
|
|
118
118
|
|
|
@@ -127,7 +127,7 @@ wb.add_worksheet(:name => 'Merging Cells') do |sheet|
|
|
|
127
127
|
sheet["A1:D1"].each { |c| c.color = "FF0000"}
|
|
128
128
|
sheet["A1:D4"].each { |c| c.style = Axlsx::STYLE_THIN_BORDER }
|
|
129
129
|
end
|
|
130
|
-
|
|
130
|
+
##```
|
|
131
131
|
|
|
132
132
|
##Add an Image with a hyperlink
|
|
133
133
|
|
|
@@ -169,7 +169,7 @@ wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
|
|
|
169
169
|
sheet.add_row ["华语/華語"]
|
|
170
170
|
sheet.add_row ["한국어/조선말"]
|
|
171
171
|
end
|
|
172
|
-
|
|
172
|
+
##```
|
|
173
173
|
|
|
174
174
|
##Using formula
|
|
175
175
|
|
|
@@ -178,7 +178,7 @@ wb.add_worksheet(:name => "Using Formulas") do |sheet|
|
|
|
178
178
|
sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4']
|
|
179
179
|
sheet.add_row [1, 2, 3, "=SUM(A2:C2)"]
|
|
180
180
|
end
|
|
181
|
-
|
|
181
|
+
##```
|
|
182
182
|
|
|
183
183
|
##Auto Filter
|
|
184
184
|
|
|
@@ -190,11 +190,13 @@ wb.add_worksheet(:name => "Auto Filter") do |sheet|
|
|
|
190
190
|
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
|
191
191
|
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
|
192
192
|
sheet.auto_filter = "A2:D5"
|
|
193
|
+
sheet.auto_filter.add_column 3, :filters, :filter_items => ['1.9.2', '1.8.7']
|
|
193
194
|
end
|
|
194
195
|
#```
|
|
195
196
|
|
|
196
197
|
##Automatic cell types
|
|
197
198
|
|
|
199
|
+
|
|
198
200
|
#```ruby
|
|
199
201
|
wb.add_worksheet(:name => "Automatic cell types") do |sheet|
|
|
200
202
|
date_format = wb.styles.add_style :format_code => 'YYYY-MM-DD'
|
|
@@ -202,9 +204,33 @@ wb.add_worksheet(:name => "Automatic cell types") do |sheet|
|
|
|
202
204
|
sheet.add_row ["Date", "Time", "String", "Boolean", "Float", "Integer"]
|
|
203
205
|
sheet.add_row [Date.today, Time.now, "value", true, 0.1, 1], :style => [date_format, time_format]
|
|
204
206
|
end
|
|
205
|
-
#```
|
|
206
207
|
|
|
207
208
|
|
|
209
|
+
# Hyperlinks in worksheet
|
|
210
|
+
wb.add_worksheet(:name => 'hyperlinks') do |sheet|
|
|
211
|
+
# external references
|
|
212
|
+
sheet.add_row ['axlsx']
|
|
213
|
+
sheet.add_hyperlink :location => 'https://github.com/randym/axlsx', :ref => sheet.rows.first.cells.first
|
|
214
|
+
# internal references
|
|
215
|
+
sheet.add_hyperlink :location => "'Next Sheet'!A1", :ref => 'A2', :target => :sheet
|
|
216
|
+
sheet.add_row ['next sheet']
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
wb.add_worksheet(:name => 'Next Sheet') do |sheet|
|
|
220
|
+
sheet.add_row ['hello!']
|
|
221
|
+
end
|
|
222
|
+
###```
|
|
223
|
+
|
|
224
|
+
##Number formatting and currency
|
|
225
|
+
wb.add_worksheet(:name => "Formats and Currency") do |sheet|
|
|
226
|
+
currency = wb.styles.add_style :num_fmt => 5
|
|
227
|
+
red_negative = wb.styles.add_style :num_fmt => 8
|
|
228
|
+
comma = wb.styles.add_style :num_fmt => 3
|
|
229
|
+
super_funk = wb.styles.add_style :format_code => '[Green]#'
|
|
230
|
+
sheet.add_row %w(Currency RedNegative Comma Custom)
|
|
231
|
+
sheet.add_row [1500, -122.34, 123456789, 594829], :style=> [currency, red_negative, comma, super_funk]
|
|
232
|
+
end
|
|
233
|
+
|
|
208
234
|
##Generating A Bar Chart
|
|
209
235
|
|
|
210
236
|
#```ruby
|
|
@@ -215,7 +241,7 @@ wb.add_worksheet(:name => "Bar Chart") do |sheet|
|
|
|
215
241
|
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :title => sheet["A1"]
|
|
216
242
|
end
|
|
217
243
|
end
|
|
218
|
-
|
|
244
|
+
##```
|
|
219
245
|
|
|
220
246
|
##Hide Gridlines in chart
|
|
221
247
|
|
|
@@ -290,7 +316,7 @@ wb.add_worksheet(:name => "Table") do |sheet|
|
|
|
290
316
|
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"]
|
|
291
317
|
sheet.add_row ["19.2", "1 min 28 sec", "about 10 hours ago", "1.9.2"]
|
|
292
318
|
sheet.add_row ["19.3", "1 min 35 sec", "about 10 hours ago", "1.9.3"]
|
|
293
|
-
sheet.add_table "A2:D5", :name => 'Build Matrix'
|
|
319
|
+
sheet.add_table "A2:D5", :name => 'Build Matrix', :style_info => { :name => "TableStyleMedium23" }
|
|
294
320
|
end
|
|
295
321
|
#```
|
|
296
322
|
|
|
@@ -447,7 +473,9 @@ p.use_shared_strings = true
|
|
|
447
473
|
p.serialize("shared_strings_example.xlsx")
|
|
448
474
|
#```
|
|
449
475
|
|
|
450
|
-
|
|
476
|
+
#p.validate do |er|
|
|
477
|
+
#puts er.inspect
|
|
478
|
+
#end
|
|
451
479
|
##Disabling Autowidth
|
|
452
480
|
|
|
453
481
|
#```ruby
|
data/examples/example.xlsx
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
4
|
+
|
|
5
|
+
#```ruby
|
|
6
|
+
require 'axlsx'
|
|
7
|
+
|
|
8
|
+
p = Axlsx::Package.new
|
|
9
|
+
wb = p.workbook
|
|
10
|
+
wb.add_worksheet(:name => 'hyperlinks') do |sheet|
|
|
11
|
+
# external references
|
|
12
|
+
sheet.add_row ['axlsx']
|
|
13
|
+
sheet.add_hyperlink :location => 'https://github.com/randym/axlsx', :ref => sheet.rows.first.cells.first
|
|
14
|
+
# internal references
|
|
15
|
+
sheet.add_row ['next sheet']
|
|
16
|
+
sheet.add_hyperlink :location => "'Next Sheet'!A1", :target => :sheet, :ref => 'A2'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
wb.add_worksheet(:name => 'Next Sheet') do |sheet|
|
|
20
|
+
sheet.add_row ['hello!']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
p.serialize 'hyperlinks.xlsx'
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
require 'axlsx'
|
|
3
|
+
xls = Axlsx::Package.new
|
|
4
|
+
wb = xls.workbook
|
|
5
|
+
wb.add_worksheet do |ws|
|
|
6
|
+
# Excel does not currently follow the specification and will ignore paper_width and paper_height so if you need
|
|
7
|
+
# to for a paper size, be sure to set :paper_size
|
|
8
|
+
ws.page_setup.set :paper_width => "210mm", :paper_size => 10, :paper_height => "297mm", :orientation => :landscape
|
|
9
|
+
ws.add_row %w(AXLSX is cool)
|
|
10
|
+
end
|
|
11
|
+
xls.serialize "page_setup.xlsx"
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
,,,,,
|
|
Binary file
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
|
|
2
2
|
|
|
3
3
|
require 'axlsx'
|
|
4
4
|
|
|
5
5
|
Axlsx::Package.new do |p|
|
|
6
6
|
p.workbook do |wb|
|
|
7
7
|
styles = wb.styles
|
|
8
|
-
header
|
|
8
|
+
header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center}
|
|
9
9
|
tbl_header = styles.add_style :b => true, :alignment => { :horizontal => :center }
|
|
10
10
|
ind_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => {:indent => 1}
|
|
11
|
-
col_header
|
|
12
|
-
label
|
|
13
|
-
money
|
|
14
|
-
t_label
|
|
15
|
-
t_money
|
|
11
|
+
col_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => { :horizontal => :center }
|
|
12
|
+
label = styles.add_style :alignment => { :indent => 1 }
|
|
13
|
+
money = styles.add_style :num_fmt => 5
|
|
14
|
+
t_label = styles.add_style :b => true, :bg_color => "FFDFDEDF"
|
|
15
|
+
t_money = styles.add_style :b => true, :num_fmt => 5, :bg_color => "FFDFDEDF"
|
|
16
16
|
|
|
17
17
|
wb.add_worksheet do |sheet|
|
|
18
18
|
sheet.add_row
|
|
@@ -54,7 +54,7 @@ Axlsx::Package.new do |p|
|
|
|
54
54
|
chart.start_at 7, 16
|
|
55
55
|
chart.end_at 12, 31
|
|
56
56
|
end
|
|
57
|
-
|
|
57
|
+
%w(B4:C4 E4:F4 B11:C11 E11:F11 B2:F2).each { |range| sheet.merge_cells(range) }
|
|
58
58
|
sheet.column_widths 2, nil, nil, 2, nil, nil, 2
|
|
59
59
|
end
|
|
60
60
|
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
|
|
2
|
+
require 'axlsx'
|
|
3
|
+
|
|
4
|
+
package = Axlsx::Package.new
|
|
5
|
+
package.workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
|
|
6
|
+
sheet.add_row ["First Column", "Second", "Third"]
|
|
7
|
+
sheet.add_row [1, 2, 3]
|
|
8
|
+
end
|
|
9
|
+
package.serialize 'basics.xlsx'
|
|
10
|
+
|
|
11
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
|
|
2
|
+
|
|
3
|
+
require 'axlsx'
|
|
4
|
+
package = Axlsx::Package.new do |package|
|
|
5
|
+
package.workbook.add_worksheet(:name => "imagex") do |sheet|
|
|
6
|
+
img_path = File.expand_path('../../image1.jpeg', __FILE__)
|
|
7
|
+
sheet.add_image(:image_src => img_path, :width => 720, :height => 666, :start_at => [2,2])
|
|
8
|
+
end
|
|
9
|
+
end.serialize 'images.xlsx'
|
|
Binary file
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env ruby -w -s
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
|
|
5
|
+
require 'axlsx'
|
|
6
|
+
|
|
7
|
+
data = [ ['oil-bbl',9591.411671,8860.714604,8237.936509,7700.523067,7231.831842,6819.307902,6453.297235,6126.251755,5832.182748,5566.276532,5324.618706,5103.992757,4901.730597,4715.600022,4543.718862,4384.488699,4236.543136,4098.707009,3969.963937,3849.430276,3736.33405,3629.997786,3529.824424,3435.28568,3345.912388,3261.286414,3181.033882,3104.819438,3032.341401,2963.327615,2897.531915,2834.731083,2774.722219,2717.320479,2662.357097,2609.677666,2559.140642,2510.616021,2463.984182,2419.134871,2375.966292,2334.384311,2294.301748,2255.637735,2218.317165,2182.270173,2147.431696,2113.741056,2081.141602,2049.580377,2019.007821,1989.377502,1960.645871,1932.772042,1905.71759,1879.446367,1853.924338,1829.119424,1805.001366,1781.541597,1758.713122,1736.490414,1714.849315,1693.766943,1673.22161,1653.192744,1633.660817,1614.607284,1596.014514,1577.865741,1560.145009,1542.837121,1525.927597,1509.402632,1493.249056,1477.454298,1462.006352,1446.893746,1432.105512,1417.631159,1403.460647,1389.584361,1375.993094,1362.678018,1349.630672,1336.842938,1324.307026,1312.015455,1299.961043,1288.136885,1276.536347,1265.153047,1253.980847,1243.013838,1232.246332,1221.672852,1211.288119,1201.087047,1191.064732,1181.216443,1171.537618,1162.023853,1152.670896,1143.474642,1134.431125,1125.536513,1116.787101,1108.179309,1099.709672,1091.37484,1083.171571,1075.096725,1067.147265,1059.320247,1051.612821,1044.022223,1036.545778,1029.180889,1021.92504,1014.775789],
|
|
8
|
+
|
|
9
|
+
['gas-mcf', 940970.153,836556.732,748476.939,673307.64,608520.158,552204.935,502892.3,459432.263,420911.806,386596.658,355889.491,328299.357,303418.988,280907.679,260478.232,241886.857,224925.287,209414.552,195200.029,182147.455,170139.707,159074.174,148860.596,139419.282,130679.626,122578.864,115061.035,108076.1,101579.19,95529.972,89892.104,84632.762,79722.24,75133.597,70842.349,66826.213,63064.865,59539.742,56233.86,53131.662,50218.869,47482.365,44910.082,42490.907,40214.588,38071.662,36053.382,34151.656,32358.989,30668.434,29073.545,27568.334,26147.237,24805.079,23537.041,22338.633,21205.67,20134.246,19120.717,18161.677,17253.941,16394.533,15580.663,14809.724,14079.269,13387.006,12730.786,12108.59,11518.524,10958.809,10427.774,9923.847,9445.55,8991.492,8560.364,8150.934,7762.041,7392.59,7041.551,6707.951,6390.874,6089.452,5802.871,5530.358,5271.185,5024.664,4790.145,4567.013,4354.687,4152.618,3960.286,3777.198,3602.889,3436.919,3278.87,3128.347,2984.976,2848.401,2718.287,2594.316,2476.184,2363.606,2256.309,2154.037,2056.545,1963.599,1874.982,1790.482,1709.903,1633.054,1559.758,1489.844,1423.151,1359.525,1298.821,1240.899,1185.628,1132.883,1082.544,1034.499],
|
|
10
|
+
|
|
11
|
+
['water-bbl',940.97,836.557,748.477,673.308,608.52,552.205,502.892,459.432,420.912,386.597,355.889,328.299,303.419,280.908,260.478,241.887,224.925,209.415,195.2,182.147,170.14,159.074,148.861,139.419,130.68,122.579,115.061,108.076,101.579,95.53,89.892,84.633,79.722,75.134,70.842,66.826,63.065,59.54,56.234,53.132,50.219,47.482,44.91,42.491,40.215,38.072,36.053,34.152,32.359,30.668,29.074,27.568,26.147,24.805,23.537,22.339,21.206,20.134,19.121,18.162,17.254,16.395,15.581,14.81,14.079,13.387,12.731,12.109,11.519,10.959,10.428,9.924,9.446,8.991,8.56,8.151,7.762,7.393,7.042,6.708,6.391,6.089,5.803,5.53,5.271,5.025,4.79,4.567,4.355,4.153,3.96,3.777,3.603,3.437,3.279,3.128,2.985,2.848,2.718,2.594,2.476,2.364,2.256,2.154,2.057,1.964,1.875,1.79,1.71,1.633,1.56,1.49,1.423,1.36,1.299,1.241,1.186,1.133,1.083,1.034] ]
|
|
12
|
+
|
|
13
|
+
package = Axlsx::Package.new
|
|
14
|
+
package.workbook.add_worksheet(:name => 'volumes') do |ws|
|
|
15
|
+
|
|
16
|
+
# perspective, rotX and rotY flatten the 3D chart
|
|
17
|
+
# hPercent sets the chart height to 100%
|
|
18
|
+
chart_options = { :perspective => 0,
|
|
19
|
+
:hPercent => 100,
|
|
20
|
+
:rotX => 0,
|
|
21
|
+
:rotY => 0,
|
|
22
|
+
:start_at => "A4",
|
|
23
|
+
:end_at => 'M44',
|
|
24
|
+
:title => 'Monthly forcast for Type Curve Gas secondary - gross ngl' }
|
|
25
|
+
|
|
26
|
+
chart = ws.add_chart(Axlsx::Line3DChart, chart_options)
|
|
27
|
+
|
|
28
|
+
# Set up log based scaling and appropriate min/max values for Y axis
|
|
29
|
+
chart.valAxis.scaling.logBase = 10
|
|
30
|
+
chart.valAxis.scaling.min = 0.1
|
|
31
|
+
chart.valAxis.scaling.max = 10000000.0
|
|
32
|
+
|
|
33
|
+
# No poing in showing the series axis labels as the chart is flattened!
|
|
34
|
+
chart.serAxis.delete = true
|
|
35
|
+
|
|
36
|
+
# Knock the catAxis labels down to the forced min.
|
|
37
|
+
chart.catAxis.crosses = :min
|
|
38
|
+
|
|
39
|
+
# set up cat labels / markes to show every 12th item
|
|
40
|
+
chart.catAxis.tickLblSkip = 12
|
|
41
|
+
chart.catAxis.tickMarkSkip = 12
|
|
42
|
+
|
|
43
|
+
#rgb colors for our data series
|
|
44
|
+
colors = ['00FF00', 'FF0000', '0000FF']
|
|
45
|
+
|
|
46
|
+
data.each_with_index do |value, index|
|
|
47
|
+
ws.add_row value
|
|
48
|
+
chart.add_series :data => ws.rows.last.cells[(1..value.size-1)],
|
|
49
|
+
:labels => (0..value.size).map{ |i| i },
|
|
50
|
+
:title => ws.rows.last.cells.first,
|
|
51
|
+
:color => colors[index]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
package.serialize 'line_chart.xlsx'
|
|
56
|
+
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
|
|
2
|
+
|
|
3
|
+
require 'axlsx'
|
|
4
|
+
package = Axlsx::Package.new
|
|
5
|
+
package.workbook do |workbook|
|
|
6
|
+
workbook.styles do |s|
|
|
7
|
+
black_cell = s.add_style :bg_color => "00", :fg_color => "FF", :sz => 14, :alignment => { :horizontal=> :center }
|
|
8
|
+
blue_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 20, :alignment => { :horizontal=> :center }
|
|
9
|
+
|
|
10
|
+
workbook.add_worksheet(:name => "Styles") do |sheet|
|
|
11
|
+
# Applies the black_cell style to the first and third cell, and the blue_cell style to the second.
|
|
12
|
+
sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
|
|
13
|
+
|
|
14
|
+
# Applies the thin border to all three cells
|
|
15
|
+
sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
package.serialize 'styles.xlsx'
|
|
20
|
+
|
|
Binary file
|