axlsx 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -5
- data/Rakefile +3 -2
- data/examples/chart_colors.rb +18 -3
- data/examples/example.rb +100 -46
- data/examples/extractive.pdf +0 -0
- data/lib/axlsx.rb +7 -6
- data/lib/axlsx/content_type/content_type.rb +2 -0
- data/lib/axlsx/content_type/default.rb +21 -12
- data/lib/axlsx/content_type/override.rb +22 -11
- data/lib/axlsx/doc_props/app.rb +36 -32
- data/lib/axlsx/doc_props/core.rb +9 -5
- data/lib/axlsx/drawing/ax_data_source.rb +7 -6
- data/lib/axlsx/drawing/axis.rb +48 -27
- data/lib/axlsx/drawing/bar_3D_chart.rb +47 -37
- data/lib/axlsx/drawing/bar_series.rb +1 -0
- data/lib/axlsx/drawing/cat_axis.rb +42 -38
- data/lib/axlsx/drawing/chart.rb +34 -27
- data/lib/axlsx/drawing/drawing.rb +5 -4
- data/lib/axlsx/drawing/line_3D_chart.rb +1 -1
- data/lib/axlsx/drawing/num_data_source.rb +1 -1
- data/lib/axlsx/drawing/pie_3D_chart.rb +7 -7
- data/lib/axlsx/drawing/two_cell_anchor.rb +3 -8
- data/lib/axlsx/drawing/view_3D.rb +41 -31
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +11 -11
- data/lib/axlsx/rels/relationship.rb +3 -3
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- data/lib/axlsx/util/constants.rb +4 -0
- data/lib/axlsx/util/simple_typed_list.rb +2 -2
- data/lib/axlsx/util/validators.rb +2 -2
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/workbook.rb +1 -2
- data/lib/axlsx/workbook/worksheet/cell.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_setup.rb +9 -0
- data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +180 -56
- data/test/content_type/tc_content_type.rb +1 -6
- data/test/doc_props/tc_core.rb +1 -1
- data/test/drawing/tc_axis.rb +8 -0
- data/test/drawing/tc_bar_3D_chart.rb +12 -12
- data/test/drawing/tc_bar_series.rb +0 -1
- data/test/drawing/tc_chart.rb +1 -5
- data/test/drawing/tc_pie_3D_chart.rb +3 -7
- data/test/drawing/tc_view_3D.rb +18 -18
- data/test/tc_package.rb +2 -0
- data/test/workbook/worksheet/tc_page_setup.rb +20 -3
- data/test/workbook/worksheet/tc_protected_range.rb +18 -0
- data/test/workbook/worksheet/tc_selection.rb +1 -1
- data/test/workbook/worksheet/tc_worksheet.rb +39 -18
- metadata +54 -103
- data/examples/axis-titles.xlsx +0 -0
- data/examples/basic_charts.xlsx +0 -0
- data/examples/chart_colors.xlsx +0 -0
- data/examples/charts.xlsx +0 -0
- data/examples/conditional_formatting/getting_barred.xlsx +0 -0
- data/examples/doc/_index.html +0 -84
- data/examples/doc/class_list.html +0 -47
- data/examples/doc/css/common.css +0 -1
- data/examples/doc/css/full_list.css +0 -55
- data/examples/doc/css/style.css +0 -322
- data/examples/doc/file_list.html +0 -46
- data/examples/doc/frames.html +0 -13
- data/examples/doc/index.html +0 -84
- data/examples/doc/js/app.js +0 -205
- data/examples/doc/js/full_list.js +0 -173
- data/examples/doc/js/jquery.js +0 -16
- data/examples/doc/method_list.html +0 -46
- data/examples/doc/top-level-namespace.html +0 -95
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/examples_saved.xlsx +0 -0
- data/examples/extractive.xlsx +0 -0
- data/examples/fish.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/pareto.rb +0 -28
- data/examples/pareto.xlsx +0 -0
- data/examples/pie_chart_excel.xlsx +0 -0
- data/examples/pie_chart_saved.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/sheet_protection.xlsx +0 -0
- data/examples/sheet_view.xlsx +0 -0
- data/examples/two_cell_anchor_image.xlsx +0 -0
- data/examples/~$example.xlsx +0 -0
- data/lib/axlsx/drawing/ax_data_source.rb~ +0 -55
- data/lib/axlsx/drawing/data_source.rb~ +0 -51
- data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
- data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
- data/lib/axlsx/drawing/num_data.rb~ +0 -51
- data/lib/axlsx/drawing/num_data_source.rb~ +0 -54
- data/lib/axlsx/drawing/num_val.rb~ +0 -40
- data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
- data/lib/axlsx/drawing/ref.rb~ +0 -41
- data/lib/axlsx/drawing/str_data.rb~ +0 -58
- data/lib/axlsx/drawing/str_val.rb~ +0 -35
- data/lib/axlsx/drawing/vml_drawing.rb~ +0 -6
- data/lib/axlsx/drawing/vml_shape.rb~ +0 -61
- data/lib/axlsx/util/cbf.rb +0 -333
- data/lib/axlsx/util/cfb.rb~ +0 -201
- data/lib/axlsx/util/font_tables.rb~ +0 -0
- data/lib/axlsx/util/ms_off_crypto.rb +0 -189
- data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
- data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
- data/lib/axlsx/util/parser.rb~ +0 -6
- data/lib/axlsx/util/storage.rb~ +0 -0
- data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
- data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb~ +0 -46
- data/lib/axlsx/workbook/worksheet/comment.rb~ +0 -91
- data/lib/axlsx/workbook/worksheet/comments.rb~ +0 -86
- data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb~ +0 -95
- data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
- data/lib/schema/dc.xsd~ +0 -118
- data/lib/schema/dcterms.xsd~ +0 -331
- data/lib/schema/opc-coreProperties.xsd~ +0 -50
- data/test/drawing/tc_data_source.rb~ +0 -30
- data/test/drawing/tc_num_data.rb~ +0 -35
- data/test/drawing/tc_num_val.rb~ +0 -29
- data/test/drawing/tc_str_data.rb~ +0 -30
- data/test/drawing/tc_str_val.rb~ +0 -26
- data/test/drawing/tc_vml_drawing.rb~ +0 -0
- data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
- data/test/workbook/worksheet/tc_cfvo.rb~ +0 -20
- data/test/workbook/worksheet/tc_col.rb~ +0 -10
- data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
- data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
- data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
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
|
+
[![Click here to lend your support to: axlsx and make a donation at www.pledgie.com !](http://www.pledgie.com/campaigns/17814.png?skin_name=chrome)](http://www.pledgie.com/campaigns/17814)
|
4
5
|
|
5
6
|
**IRC**:[irc.freenode.net / #axlsx](irc://irc.freenode.net/axlsx)
|
6
7
|
|
@@ -16,7 +17,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
16
17
|
|
17
18
|
**License**: MIT License
|
18
19
|
|
19
|
-
**Latest Version**: 1.1.
|
20
|
+
**Latest Version**: 1.1.8
|
20
21
|
|
21
22
|
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
|
22
23
|
|
@@ -24,7 +25,7 @@ Axlsx: Office Open XML Spreadsheet Generation
|
|
24
25
|
|
25
26
|
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
|
26
27
|
|
27
|
-
**Release Date**:
|
28
|
+
**Release Date**: July 14th 2012
|
28
29
|
|
29
30
|
If you are working in rails, or with active record see:
|
30
31
|
http://github.com/randym/acts_as_xlsx
|
@@ -69,8 +70,6 @@ Feature List
|
|
69
70
|
**10. Support for formulas, merging, row and column outlining as well as
|
70
71
|
cell level input data validation.
|
71
72
|
|
72
|
-
**11. Support for cell merging as well as column and row outline
|
73
|
-
|
74
73
|
**12. Auto filtering tables with worksheet.auto_filter as well as support for Tables
|
75
74
|
|
76
75
|
**13. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).
|
@@ -81,6 +80,9 @@ cell level input data validation.
|
|
81
80
|
|
82
81
|
**16. Support for password and non password based sheet protection.
|
83
82
|
|
83
|
+
**17. First stage interoperability support for GoogleDocs, LibraOffice,
|
84
|
+
and Numbers
|
85
|
+
|
84
86
|
Installing
|
85
87
|
----------
|
86
88
|
|
@@ -93,7 +95,7 @@ To install Axlsx, use the following command:
|
|
93
95
|
|
94
96
|
The example listing is getting overly large to maintain here.
|
95
97
|
If you are using Yard, you will be able to see the examples in line below.
|
96
|
-
If not, please refer to the Please see the
|
98
|
+
If not, please refer to the Please see the [examples](https://github.com/randym/axlsx/tree/master/examples/example.rb) here.
|
97
99
|
|
98
100
|
{include:file:examples/example.rb}
|
99
101
|
|
@@ -113,6 +115,15 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
|
|
113
115
|
|
114
116
|
#Change log
|
115
117
|
---------
|
118
|
+
- **July.14.12**: 1.1.8 release
|
119
|
+
- added html entity encoding for sheet names. This allows you to use
|
120
|
+
characters like '<' and '&' in your sheet names.
|
121
|
+
- new - first round google docs interoperability
|
122
|
+
- added filter to strip out control characters from cell data.
|
123
|
+
- added in interop requirements so that charts are properly exported
|
124
|
+
to PDF from Libra Office
|
125
|
+
- various readability improvements and work standardizing attribute
|
126
|
+
names to snake_case. Aliases are provided for backward compatiblity
|
116
127
|
- **June.11.12**: 1.1.7 release
|
117
128
|
- fix chart rendering issue when label offset is specified as a
|
118
129
|
percentage in serialization and ensure that formula are not stored
|
@@ -163,6 +174,29 @@ in value caches
|
|
163
174
|
|
164
175
|
Please see the {file:CHANGELOG.md} document for past release information.
|
165
176
|
|
177
|
+
# Known interoperability issues.
|
178
|
+
As axslx implements the Office Open XML (ECMA-376 spec) much of the
|
179
|
+
functionality is interoperable with other spreadsheet software. Below is
|
180
|
+
a listing of some known issues.
|
181
|
+
|
182
|
+
1. Libra Office
|
183
|
+
- You must specify colors for your series. see examples/chart_colors.rb
|
184
|
+
for an example.
|
185
|
+
- You must use data in your sheet for charts. You cannot use hard coded
|
186
|
+
values.
|
187
|
+
- Chart axis and gridlines do not render. I have a feeling this is
|
188
|
+
related to themes, which axlsx does not implement at this time.
|
189
|
+
|
190
|
+
2. Google Docs
|
191
|
+
- Images are known to not work with google docs
|
192
|
+
- border colors do not work
|
193
|
+
- Charts, for the most part, do not work. Google docs has some specific requirements about how the worksheet is set up to create a chart.
|
194
|
+
|
195
|
+
3. Numbers
|
196
|
+
- you must set 'use_shared_strings' to true
|
197
|
+
- charts do not render
|
198
|
+
|
199
|
+
|
166
200
|
#Thanks!
|
167
201
|
|
168
202
|
Open source software is a community effort. None of this could have been
|
@@ -191,6 +225,8 @@ done without the help of the people below.
|
|
191
225
|
|
192
226
|
[janhuehne](https://github.com/janhuehne) - for working out the decoder ring and adding in cell level validation, and providing a support for window panes.
|
193
227
|
|
228
|
+
[rfc2616](https://github.com/rfc2616) - for FINALLY working out the interop issues with google docs.
|
229
|
+
|
194
230
|
#Copyright and License
|
195
231
|
----------
|
196
232
|
|
data/Rakefile
CHANGED
@@ -9,8 +9,9 @@ task :benchmark do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
task :gendoc do
|
12
|
-
|
13
|
-
system "
|
12
|
+
puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
|
13
|
+
# system "yardoc"
|
14
|
+
# system "yard stats --list-undoc"
|
14
15
|
end
|
15
16
|
|
16
17
|
task :test do
|
data/examples/chart_colors.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby -w -s
|
2
2
|
# -*- coding: utf-8 -*-
|
3
|
-
|
3
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
4
|
require 'axlsx'
|
5
5
|
|
6
6
|
p = Axlsx::Package.new
|
@@ -36,7 +36,7 @@ end
|
|
36
36
|
sheet.add_row ["First", "Second", "Third", "Fourth"]
|
37
37
|
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
|
38
38
|
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title => "example 3: Pie Chart") do |chart|
|
39
|
-
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF']
|
39
|
+
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"], :colors => ['FF0000', '00FF00', '0000FF', '000000']
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -45,7 +45,7 @@ end
|
|
45
45
|
wb.add_worksheet(:name => "Line Chart") do |sheet|
|
46
46
|
sheet.add_row ["First", 1, 5, 7, 9]
|
47
47
|
sheet.add_row ["Second", 5, 2, 14, 9]
|
48
|
-
sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY =>
|
48
|
+
sheet.add_chart(Axlsx::Line3DChart, :title => "example 6: Line Chart", :rotX => 30, :rotY => 30) do |chart|
|
49
49
|
chart.start_at 0, 2
|
50
50
|
chart.end_at 10, 15
|
51
51
|
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000"
|
@@ -53,6 +53,21 @@ wb.add_worksheet(:name => "Line Chart") do |sheet|
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
wb.add_worksheet(:name => 'Line Chart with Axis colors') do |sheet|
|
57
|
+
sheet.add_row ["First", 1, 5, 7, 9]
|
58
|
+
sheet.add_row ["Second", 5, 2, 14, 9]
|
59
|
+
sheet.add_chart(Axlsx::Line3DChart, :title => "example 7: Flat Line Chart", :rot_x => 0, :perspective => 0) do |chart|
|
60
|
+
chart.valAxis.color = "FFFF00"
|
61
|
+
chart.catAxis.color = "00FFFF"
|
62
|
+
chart.serAxis.delete = true
|
63
|
+
chart.start_at 0, 2
|
64
|
+
chart.end_at 10, 15
|
65
|
+
chart.add_series :data => sheet["B1:E1"], :title => sheet["A1"], :color => "FF0000"
|
66
|
+
chart.add_series :data => sheet["B2:E2"], :title => sheet["A2"], :color => "00FF00"
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
56
71
|
##Generating A Scatter Chart
|
57
72
|
|
58
73
|
wb.add_worksheet(:name => "Scatter Chart") do |sheet|
|
data/examples/example.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby -w -s
|
2
2
|
# -*- coding: utf-8 -*-
|
3
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
3
|
+
# $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
4
4
|
|
5
5
|
#```ruby
|
6
6
|
require 'axlsx'
|
@@ -210,12 +210,9 @@ end
|
|
210
210
|
#```ruby
|
211
211
|
wb.add_worksheet(:name => "Bar Chart") do |sheet|
|
212
212
|
sheet.add_row ["A Simple Bar Chart"]
|
213
|
-
sheet.add_row [
|
214
|
-
sheet.
|
215
|
-
|
216
|
-
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
217
|
-
chart.valAxis.label_rotation = -45
|
218
|
-
chart.catAxis.label_rotation = 45
|
213
|
+
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
214
|
+
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
|
215
|
+
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :title => sheet["A1"]
|
219
216
|
end
|
220
217
|
end
|
221
218
|
#```
|
@@ -224,11 +221,10 @@ end
|
|
224
221
|
|
225
222
|
#```ruby
|
226
223
|
wb.add_worksheet(:name => "Chart With No Gridlines") do |sheet|
|
227
|
-
sheet.add_row ["
|
228
|
-
sheet.add_row [
|
229
|
-
sheet.
|
230
|
-
|
231
|
-
chart.add_series :data => sheet["A3:C3"], :labels => sheet["A2:C2"], :title => sheet["A1"]
|
224
|
+
sheet.add_row ["Bar Chart without gridlines"]
|
225
|
+
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
226
|
+
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
|
227
|
+
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"]
|
232
228
|
chart.valAxis.gridlines = false
|
233
229
|
chart.catAxis.gridlines = false
|
234
230
|
end
|
@@ -239,28 +235,10 @@ end
|
|
239
235
|
|
240
236
|
#```ruby
|
241
237
|
wb.add_worksheet(:name => "Pie Chart") do |sheet|
|
242
|
-
sheet.add_row ["
|
243
|
-
sheet.add_row [
|
244
|
-
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,
|
245
|
-
chart.add_series :data => sheet["
|
246
|
-
end
|
247
|
-
end
|
248
|
-
#```
|
249
|
-
|
250
|
-
##Data over time
|
251
|
-
|
252
|
-
#```ruby
|
253
|
-
wb.add_worksheet(:name=>'Charting Dates') do |sheet|
|
254
|
-
# cell level style overides when adding cells
|
255
|
-
sheet.add_row ['Date', 'Value'], :sz => 16
|
256
|
-
sheet.add_row [Time.now - (7*60*60*24), 3]
|
257
|
-
sheet.add_row [Time.now - (6*60*60*24), 7]
|
258
|
-
sheet.add_row [Time.now - (5*60*60*24), 18]
|
259
|
-
sheet.add_row [Time.now - (4*60*60*24), 1]
|
260
|
-
sheet.add_chart(Axlsx::Bar3DChart) do |chart|
|
261
|
-
chart.start_at "B7"
|
262
|
-
chart.end_at "H27"
|
263
|
-
chart.add_series(:data => sheet["B2:B5"], :labels => sheet["A2:A5"], :title => sheet["B1"])
|
238
|
+
sheet.add_row ["Simple Pie Chart"]
|
239
|
+
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
|
240
|
+
sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
|
241
|
+
chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"]
|
264
242
|
end
|
265
243
|
end
|
266
244
|
#```
|
@@ -269,15 +247,18 @@ end
|
|
269
247
|
|
270
248
|
#```ruby
|
271
249
|
wb.add_worksheet(:name => "Line Chart") do |sheet|
|
272
|
-
sheet.add_row ["
|
273
|
-
sheet.add_row
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
chart.
|
279
|
-
chart.
|
280
|
-
chart.
|
250
|
+
sheet.add_row ["Simple Line Chart"]
|
251
|
+
sheet.add_row %w(first second)
|
252
|
+
4.times do
|
253
|
+
sheet.add_row [ rand(24)+1, rand(24)+1]
|
254
|
+
end
|
255
|
+
sheet.add_chart(Axlsx::Line3DChart, :title => "Simple Line Chart", :rotX => 30, :rotY => 20) do |chart|
|
256
|
+
chart.start_at 0, 5
|
257
|
+
chart.end_at 10, 20
|
258
|
+
chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"]
|
259
|
+
chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"]
|
260
|
+
chart.catAxis.title = 'X Axis'
|
261
|
+
chart.valAxis.title = 'Y Axis'
|
281
262
|
end
|
282
263
|
end
|
283
264
|
#```
|
@@ -321,7 +302,7 @@ wb.add_worksheet(:name => "fit to page") do |sheet|
|
|
321
302
|
sheet.add_row ['this all goes on one page']
|
322
303
|
sheet.fit_to_page = true
|
323
304
|
end
|
324
|
-
|
305
|
+
##```
|
325
306
|
|
326
307
|
|
327
308
|
##Hide Gridlines in worksheet
|
@@ -331,7 +312,16 @@ wb.add_worksheet(:name => "No Gridlines") do |sheet|
|
|
331
312
|
sheet.add_row ["This", "Sheet", "Hides", "Gridlines"]
|
332
313
|
sheet.show_gridlines = false
|
333
314
|
end
|
334
|
-
|
315
|
+
##```
|
316
|
+
|
317
|
+
|
318
|
+
# Sheet Protection and excluding cells from locking.
|
319
|
+
unlocked = wb.styles.add_style :locked => false
|
320
|
+
wb.add_worksheet(:name => 'Sheet Protection') do |sheet|
|
321
|
+
sheet.sheet_protection.password = 'fish'
|
322
|
+
sheet.add_row [1, 2 ,3] # These cells will be locked
|
323
|
+
sheet.add_row [4, 5, 6], :style => unlocked # these cells will not!
|
324
|
+
end
|
335
325
|
|
336
326
|
|
337
327
|
##Specify page margins and other options for printing
|
@@ -355,7 +345,7 @@ end
|
|
355
345
|
## Frozen/Split panes
|
356
346
|
## ``` ruby
|
357
347
|
wb.add_worksheet(:name => 'fixed headers') do |sheet|
|
358
|
-
|
348
|
+
sheet.add_row(['', (0..99).map { |i| "column header #{i}" }].flatten )
|
359
349
|
100.times.with_index { |index| sheet << ["row header", (0..index).to_a].flatten }
|
360
350
|
sheet.sheet_view.pane do |pane|
|
361
351
|
pane.top_left_cell = "B2"
|
@@ -366,6 +356,70 @@ wb.add_worksheet(:name => 'fixed headers') do |sheet|
|
|
366
356
|
end
|
367
357
|
end
|
368
358
|
|
359
|
+
# conditional formatting
|
360
|
+
#
|
361
|
+
percent = wb.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
|
362
|
+
money = wb.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
|
363
|
+
|
364
|
+
# define the style for conditional formatting
|
365
|
+
profitable = wb.styles.add_style( :fg_color=>"FF428751",
|
366
|
+
:type => :dxf)
|
367
|
+
|
368
|
+
wb.add_worksheet(:name => "Conditional Cell Is") do |ws|
|
369
|
+
|
370
|
+
# Generate 20 rows of data
|
371
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
372
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
373
|
+
offset = 3
|
374
|
+
rows = 20
|
375
|
+
offset.upto(rows + offset) do |i|
|
376
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
377
|
+
end
|
378
|
+
|
379
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
380
|
+
ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
|
381
|
+
end
|
382
|
+
|
383
|
+
wb.add_worksheet(:name => "Conditional Color Scale") do |ws|
|
384
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
385
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
386
|
+
offset = 3
|
387
|
+
rows = 20
|
388
|
+
offset.upto(rows + offset) do |i|
|
389
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
390
|
+
end
|
391
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
392
|
+
color_scale = Axlsx::ColorScale.new
|
393
|
+
ws.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale })
|
394
|
+
end
|
395
|
+
|
396
|
+
|
397
|
+
wb.add_worksheet(:name => "Conditional Data Bar") do |ws|
|
398
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
399
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
400
|
+
offset = 3
|
401
|
+
rows = 20
|
402
|
+
offset.upto(rows + offset) do |i|
|
403
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
404
|
+
end
|
405
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
406
|
+
data_bar = Axlsx::DataBar.new
|
407
|
+
ws.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar })
|
408
|
+
end
|
409
|
+
|
410
|
+
wb.add_worksheet(:name => "Conditional Format Icon Set") do |ws|
|
411
|
+
ws.add_row ["Previous Year Quarterly Profits (JPY)"]
|
412
|
+
ws.add_row ["Quarter", "Profit", "% of Total"]
|
413
|
+
offset = 3
|
414
|
+
rows = 20
|
415
|
+
offset.upto(rows + offset) do |i|
|
416
|
+
ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent]
|
417
|
+
end
|
418
|
+
# Apply conditional formatting to range B3:B100 in the worksheet
|
419
|
+
icon_set = Axlsx::IconSet.new
|
420
|
+
ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
|
421
|
+
end
|
422
|
+
|
369
423
|
##Validate and Serialize
|
370
424
|
|
371
425
|
#```ruby
|
Binary file
|
data/lib/axlsx.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
require 'htmlentities'
|
2
3
|
require 'axlsx/version.rb'
|
3
4
|
|
4
5
|
require 'axlsx/util/simple_typed_list.rb'
|
5
6
|
require 'axlsx/util/constants.rb'
|
6
7
|
require 'axlsx/util/validators.rb'
|
7
8
|
|
8
|
-
#not even close to being ready but it does not break anything so it stays for now.
|
9
|
-
# needs a full re-write to use agile-encryption properly
|
10
|
-
# require 'axlsx/util/storage.rb'
|
11
|
-
# require 'axlsx/util/cbf.rb'
|
12
|
-
# require 'axlsx/util/ms_off_crypto.rb'
|
13
|
-
|
14
9
|
# to be included with parsable intitites.
|
15
10
|
#require 'axlsx/util/parser.rb'
|
16
11
|
|
@@ -53,6 +48,12 @@ module Axlsx
|
|
53
48
|
ref
|
54
49
|
end
|
55
50
|
|
51
|
+
#global reference html entity encoding
|
52
|
+
# @return [HtmlEntities]
|
53
|
+
def self.coder
|
54
|
+
@@coder ||= ::HTMLEntities.new
|
55
|
+
end
|
56
|
+
|
56
57
|
# returns the x, y position of a cell
|
57
58
|
def self.name_to_indices(name)
|
58
59
|
raise ArgumentError, 'invalid cell name' unless name.size > 1
|
@@ -1,8 +1,23 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
module Axlsx
|
3
|
+
|
3
4
|
# An default content part. These parts are automatically created by for you based on the content of your package.
|
4
5
|
class Default
|
5
6
|
|
7
|
+
#Creates a new Default object
|
8
|
+
# @option options [String] extension
|
9
|
+
# @option options [String] content_type
|
10
|
+
# @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
|
11
|
+
def initialize(options={})
|
12
|
+
raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
|
13
|
+
options.each do |name, value|
|
14
|
+
self.send("#{name}=", value) if self.respond_to? "#{name}="
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Error string for option validation
|
19
|
+
INVALID_ARGUMENTS = "extension and content_type are required"
|
20
|
+
|
6
21
|
# The extension of the content type.
|
7
22
|
# @return [String]
|
8
23
|
attr_reader :extension
|
@@ -13,18 +28,6 @@ module Axlsx
|
|
13
28
|
attr_reader :content_type
|
14
29
|
alias :ContentType :content_type
|
15
30
|
|
16
|
-
#Creates a new Default object
|
17
|
-
# @option options [String] extension
|
18
|
-
# @option options [String] content_type
|
19
|
-
# @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
|
20
|
-
def initialize(options={})
|
21
|
-
raise ArgumentError, "extension and content_type are required" unless (options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
|
22
|
-
options.each do |o|
|
23
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
31
|
# Sets the file extension for this content type.
|
29
32
|
def extension=(v) Axlsx::validate_string v; @extension = v end
|
30
33
|
alias :Extension= :extension=
|
@@ -43,5 +46,11 @@ module Axlsx
|
|
43
46
|
str << '/>'
|
44
47
|
end
|
45
48
|
|
49
|
+
private
|
50
|
+
def validate_options(options)
|
51
|
+
(options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
|
52
|
+
end
|
53
|
+
|
46
54
|
end
|
55
|
+
|
47
56
|
end
|