axlsx 1.2.0 → 1.3.3
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 +47 -33
- data/Rakefile +1 -1
- data/examples/auto_filter.rb +16 -0
- data/examples/basic_charts.rb +4 -0
- data/examples/colored_links.rb +59 -0
- data/examples/doc/_index.html +88 -0
- data/examples/doc/class_list.html +53 -0
- data/examples/doc/css/common.css +1 -0
- data/examples/doc/css/full_list.css +57 -0
- data/examples/doc/css/style.css +328 -0
- data/examples/doc/file_list.html +52 -0
- data/examples/doc/frames.html +28 -0
- data/examples/doc/index.html +88 -0
- data/examples/doc/js/app.js +214 -0
- data/examples/doc/js/full_list.js +173 -0
- data/examples/doc/js/jquery.js +4 -0
- data/examples/doc/method_list.html +52 -0
- data/examples/doc/top-level-namespace.html +102 -0
- data/examples/example.rb +447 -257
- data/examples/finance.rb +82 -0
- data/examples/hyperlinks.rb +23 -0
- data/examples/page_setup.rb +11 -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/{example.xlsx → 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/lib/axlsx/content_type/abstract_content_type.rb +32 -0
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/content_type/default.rb +6 -37
- data/lib/axlsx/content_type/override.rb +6 -38
- data/lib/axlsx/doc_props/app.rb +10 -7
- data/lib/axlsx/drawing/axis.rb +4 -4
- data/lib/axlsx/drawing/chart.rb +2 -3
- data/lib/axlsx/drawing/d_lbls.rb +21 -31
- data/lib/axlsx/drawing/drawing.rb +6 -0
- data/lib/axlsx/drawing/hyperlink.rb +40 -32
- data/lib/axlsx/drawing/marker.rb +13 -13
- data/lib/axlsx/drawing/num_data.rb +6 -6
- data/lib/axlsx/drawing/num_data_source.rb +17 -16
- data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
- data/lib/axlsx/drawing/pic.rb +25 -27
- data/lib/axlsx/drawing/picture_locking.rb +12 -44
- data/lib/axlsx/drawing/scaling.rb +13 -13
- data/lib/axlsx/drawing/scatter_chart.rb +3 -3
- data/lib/axlsx/drawing/series.rb +3 -6
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +7 -8
- data/lib/axlsx/drawing/view_3D.rb +52 -38
- data/lib/axlsx/drawing/vml_shape.rb +23 -23
- data/lib/axlsx/package.rb +14 -17
- data/lib/axlsx/stylesheet/border.rb +29 -20
- data/lib/axlsx/stylesheet/border_pr.rb +5 -4
- data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
- data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
- data/lib/axlsx/stylesheet/cell_style.rb +19 -14
- data/lib/axlsx/stylesheet/color.rb +19 -16
- data/lib/axlsx/stylesheet/dxf.rb +4 -4
- data/lib/axlsx/stylesheet/font.rb +22 -22
- data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
- data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
- data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
- data/lib/axlsx/stylesheet/styles.rb +11 -2
- data/lib/axlsx/stylesheet/table_style.rb +17 -16
- data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
- data/lib/axlsx/stylesheet/table_styles.rb +14 -11
- data/lib/axlsx/stylesheet/xf.rb +28 -26
- data/lib/axlsx/util/accessors.rb +49 -0
- data/lib/axlsx/util/constants.rb +105 -4
- data/lib/axlsx/util/options_parser.rb +15 -0
- data/lib/axlsx/util/serialized_attributes.rb +46 -0
- data/lib/axlsx/util/simple_typed_list.rb +16 -2
- data/lib/axlsx/util/validators.rb +33 -8
- data/lib/axlsx/version.rb +2 -2
- data/lib/axlsx/workbook/defined_name.rb +13 -58
- data/lib/axlsx/workbook/workbook.rb +33 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +82 -45
- data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
- data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
- data/lib/axlsx/workbook/worksheet/col.rb +34 -27
- data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
- data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
- data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
- data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
- data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
- data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
- data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
- data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
- data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +48 -81
- data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
- data/lib/axlsx/workbook/worksheet/table.rb +22 -17
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +51 -14
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +79 -0
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
- data/lib/axlsx.rb +19 -5
- data/test/content_type/tc_default.rb +0 -11
- data/test/content_type/tc_override.rb +0 -13
- data/test/drawing/tc_d_lbls.rb +14 -4
- data/test/stylesheet/tc_styles.rb +13 -0
- data/test/tc_axlsx.rb +20 -2
- data/test/tc_package.rb +1 -0
- data/test/util/tc_validators.rb +22 -1
- data/test/workbook/tc_defined_name.rb +2 -2
- data/test/workbook/tc_workbook.rb +15 -0
- 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 +35 -5
- data/test/workbook/worksheet/tc_col.rb +11 -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_pane.rb +5 -45
- data/test/workbook/worksheet/tc_row.rb +4 -4
- data/test/workbook/worksheet/tc_selection.rb +9 -48
- 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 +74 -10
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
data/examples/finance.rb
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
require 'axlsx'
|
|
5
|
+
|
|
6
|
+
# First thing to do is setup our styles. OOXML Style management is unfortunately very different from CSS so we want to use the
|
|
7
|
+
# add_style helper method on the workbook styles object so we dont go insane.
|
|
8
|
+
|
|
9
|
+
# I find it easier to declare a hash and then feed that in later
|
|
10
|
+
|
|
11
|
+
class FinancialReport
|
|
12
|
+
|
|
13
|
+
def initialize(data)
|
|
14
|
+
create_styles
|
|
15
|
+
prepare
|
|
16
|
+
insert_data data
|
|
17
|
+
finalize
|
|
18
|
+
package
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def style_hash
|
|
22
|
+
|
|
23
|
+
sienna = 'A0522D'
|
|
24
|
+
{
|
|
25
|
+
:search_results => { :sz => 10, :b => true },
|
|
26
|
+
:bold_header => { :b => true },
|
|
27
|
+
:grey_bg => { :bg_color => "DEDEDE" },
|
|
28
|
+
:transaction__header => { :fg_color => sienna, :b => true },
|
|
29
|
+
:transaction_currency => { :fb_color => sienna, :num_fmt => 5 },
|
|
30
|
+
:transactin_date => { :fg_color => sienna, :format_code => 'yyyy-mm-dd' }
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def styles
|
|
35
|
+
@styles ||= {}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def package
|
|
39
|
+
@package ||= Axlsx::Package.new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Just a place to put some defualt data for the exercise
|
|
43
|
+
def self.data
|
|
44
|
+
@data = ['baked',
|
|
45
|
+
"American Medical Systems Holdings, Inc.",
|
|
46
|
+
"Endo Pharmaceuticals Holdings, Inc.",
|
|
47
|
+
"4371",
|
|
48
|
+
Date.new,
|
|
49
|
+
2757001160,
|
|
50
|
+
2519495160,
|
|
51
|
+
116,
|
|
52
|
+
3842,
|
|
53
|
+
"Medical devices for urology disorders"]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Populates an array of ['style_name'] = style_index
|
|
57
|
+
def create_styles
|
|
58
|
+
package.workbook.styles do |style|
|
|
59
|
+
style_hash.each do |key, value|
|
|
60
|
+
styles[key] = style.add_style(value)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
def prepare
|
|
65
|
+
package.workbook.add_worksheet(:name => 'All Information') do |sheet|
|
|
66
|
+
sheet.add_row [nil, 'Search Results'], :style => [nil, styles['search_results']]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def insert_data(data)
|
|
72
|
+
package.workbook.worksheets.first do |sheet|
|
|
73
|
+
sheet.add_row data, style=> [styles[:
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def finalize
|
|
78
|
+
# package.serialize 'financial.xlsx'
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
f = FinancialReport.new(FinancialReport.data)
|
|
82
|
+
f.package.serialize 'finance.xlsx'
|
|
@@ -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'
|
|
@@ -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"
|
|
@@ -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
|
data/examples/styles.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
|
2
|
+
require 'axlsx'
|
|
3
|
+
require 'date'
|
|
4
|
+
|
|
5
|
+
p = Axlsx::Package.new
|
|
6
|
+
wb = p.workbook
|
|
7
|
+
wb.styles do |style|
|
|
8
|
+
|
|
9
|
+
# Date/Time Styles
|
|
10
|
+
#
|
|
11
|
+
# The most important thing to remember about OOXML styles is that they are
|
|
12
|
+
# exclusive. This means that each style must define all the components it
|
|
13
|
+
# requires to render the cell the way you want. A good example of this is
|
|
14
|
+
# changing the font size for a date. You cannot specify just the font size,
|
|
15
|
+
# you must also specify the number format or format code so that renders
|
|
16
|
+
# know how to display the serialized date float value
|
|
17
|
+
#
|
|
18
|
+
# The parts that make up a custom styles are:
|
|
19
|
+
#
|
|
20
|
+
# fonts(Font), fills(Fill), borders(Border) and number formats(NumFmt).
|
|
21
|
+
# Getting to know those classes will help you make the most out of custom
|
|
22
|
+
# styling. However axlsx certainly does not expect you to create all those
|
|
23
|
+
# objects manually.
|
|
24
|
+
#
|
|
25
|
+
# workbook.styles.add_style provides a helper method 'add_style' for defining
|
|
26
|
+
# styles in one go. The docs for that method are definitely worth a read.
|
|
27
|
+
# @see Style#add_style
|
|
28
|
+
|
|
29
|
+
# When no style is applied to a cell, axlsx will automatically apply date/time
|
|
30
|
+
# formatting to Date and Time objects for you. However, if you are defining
|
|
31
|
+
# custom styles, you define all aspects of the style you want to apply.
|
|
32
|
+
#
|
|
33
|
+
# An aside on styling and auto-width. Auto-width calculations do not
|
|
34
|
+
# currently take into account any style or formatting you have applied to the
|
|
35
|
+
# data in your cells as it would require the creation of a rendering engine,
|
|
36
|
+
# and frankly kill performance. If you are doing a lot of custom formatting,
|
|
37
|
+
# you are going to be better served by specifying fixed column widths.
|
|
38
|
+
#
|
|
39
|
+
# Let's look at an example:
|
|
40
|
+
#
|
|
41
|
+
# A style that only applies a font size
|
|
42
|
+
large_font = wb.styles.add_style :sz => 20
|
|
43
|
+
|
|
44
|
+
# A style that applies both a font size and a predefined number format.
|
|
45
|
+
# @see NumFmt
|
|
46
|
+
predefined_format = wb.styles.add_style :sz => 20, :num_fmt => 14
|
|
47
|
+
|
|
48
|
+
# A style that a applies a font size and a custom formatting code
|
|
49
|
+
custom_format = wb.styles.add_style :sz => 20, :format_code => 'yyyy-mm-dd'
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
wb.add_worksheet do |sheet|
|
|
53
|
+
|
|
54
|
+
# We then apply those styles positionally
|
|
55
|
+
sheet.add_row [123, "123", Time.now], style: [nil, large_font, predefined_format]
|
|
56
|
+
sheet.add_row [123, "123", Date.new(2012, 9, 14)], style: [large_font, nil, custom_format]
|
|
57
|
+
sheet.add_row [123, "123", Date.new(2000, 9, 12)] # This uses the axlsx default format_code (14)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
p.serialize 'styles.xlsx'
|
|
62
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
|
|
3
|
+
# This class extracts the common parts from Default and Override
|
|
4
|
+
class AbstractContentType
|
|
5
|
+
|
|
6
|
+
include Axlsx::OptionsParser
|
|
7
|
+
|
|
8
|
+
# Initializes an abstract content type
|
|
9
|
+
# @see Default, Override
|
|
10
|
+
def initialize(options={})
|
|
11
|
+
parse_options options
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# The type of content.
|
|
15
|
+
# @return [String]
|
|
16
|
+
attr_reader :content_type
|
|
17
|
+
alias :ContentType :content_type
|
|
18
|
+
|
|
19
|
+
# The content type.
|
|
20
|
+
# @see Axlsx#validate_content_type
|
|
21
|
+
def content_type=(v) Axlsx::validate_content_type v; @content_type = v end
|
|
22
|
+
alias :ContentType= :content_type=
|
|
23
|
+
|
|
24
|
+
# Serialize the contenty type to xml
|
|
25
|
+
def to_xml_string(node_name = '', str = '')
|
|
26
|
+
str << "<#{node_name} "
|
|
27
|
+
str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
|
|
28
|
+
str << '/>'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -2,55 +2,24 @@
|
|
|
2
2
|
module Axlsx
|
|
3
3
|
|
|
4
4
|
# An default content part. These parts are automatically created by for you based on the content of your package.
|
|
5
|
-
class Default
|
|
5
|
+
class Default < AbstractContentType
|
|
6
6
|
|
|
7
|
-
#
|
|
8
|
-
|
|
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"
|
|
7
|
+
# The serialization node name for this class
|
|
8
|
+
NODE_NAME = 'Default'
|
|
20
9
|
|
|
21
10
|
# The extension of the content type.
|
|
22
11
|
# @return [String]
|
|
23
12
|
attr_reader :extension
|
|
24
13
|
alias :Extension :extension
|
|
25
14
|
|
|
26
|
-
# The type of content.
|
|
27
|
-
# @return [String]
|
|
28
|
-
attr_reader :content_type
|
|
29
|
-
alias :ContentType :content_type
|
|
30
|
-
|
|
31
15
|
# Sets the file extension for this content type.
|
|
32
16
|
def extension=(v) Axlsx::validate_string v; @extension = v end
|
|
33
17
|
alias :Extension= :extension=
|
|
34
18
|
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
alias :ContentType= :content_type=
|
|
39
|
-
|
|
40
|
-
# Serializes the object
|
|
41
|
-
# @param [String] str
|
|
42
|
-
# @return [String]
|
|
43
|
-
def to_xml_string(str = '')
|
|
44
|
-
str << '<Default '
|
|
45
|
-
str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
|
|
46
|
-
str << '/>'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
def validate_options(options)
|
|
51
|
-
(options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
|
|
19
|
+
# Serializes this object to xml
|
|
20
|
+
def to_xml_string(str ='')
|
|
21
|
+
super(NODE_NAME, str)
|
|
52
22
|
end
|
|
53
|
-
|
|
54
23
|
end
|
|
55
24
|
|
|
56
25
|
end
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
+
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
module Axlsx
|
|
3
4
|
|
|
4
5
|
# An override content part. These parts are automatically created by for you based on the content of your package.
|
|
5
|
-
class Override
|
|
6
|
-
|
|
7
|
-
#Creates a new Override object
|
|
8
|
-
# @option options [String] PartName
|
|
9
|
-
# @option options [String] ContentType
|
|
10
|
-
# @raise [ArgumentError] An argument error is raised if both PartName and ContentType 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
|
|
6
|
+
class Override < AbstractContentType
|
|
17
7
|
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# The type of content.
|
|
22
|
-
# @return [String]
|
|
23
|
-
attr_reader :content_type
|
|
24
|
-
alias :ContentType :content_type
|
|
8
|
+
# Serialization node name for this object
|
|
9
|
+
NODE_NAME = 'Override'
|
|
25
10
|
|
|
26
11
|
# The name and location of the part.
|
|
27
12
|
# @return [String]
|
|
@@ -32,26 +17,9 @@ module Axlsx
|
|
|
32
17
|
def part_name=(v) Axlsx::validate_string v; @part_name = v end
|
|
33
18
|
alias :PartName= :part_name=
|
|
34
19
|
|
|
35
|
-
#
|
|
36
|
-
# @see Axlsx#validate_content_type
|
|
37
|
-
def content_type=(v) Axlsx::validate_content_type v; @content_type = v end
|
|
38
|
-
alias :ContentType= :content_type=
|
|
39
|
-
|
|
40
|
-
# Serializes the object
|
|
41
|
-
# @param [String] str
|
|
42
|
-
# @return [String]
|
|
20
|
+
# Serializes this object to xml
|
|
43
21
|
def to_xml_string(str = '')
|
|
44
|
-
str
|
|
45
|
-
str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
|
|
46
|
-
str << '/>'
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
def validate_options(options)
|
|
52
|
-
(options[:PartName] || options[:part_name]) && (options[:ContentType] || options[:content_type])
|
|
22
|
+
super(NODE_NAME, str)
|
|
53
23
|
end
|
|
54
|
-
|
|
55
24
|
end
|
|
56
|
-
|
|
57
25
|
end
|
data/lib/axlsx/doc_props/app.rb
CHANGED
|
@@ -11,6 +11,8 @@ module Axlsx
|
|
|
11
11
|
# DigSig (DigSigBlob)
|
|
12
12
|
class App
|
|
13
13
|
|
|
14
|
+
include Axlsx::OptionsParser
|
|
15
|
+
|
|
14
16
|
# Creates an App object
|
|
15
17
|
# @option options [String] template
|
|
16
18
|
# @option options [String] manager
|
|
@@ -35,9 +37,7 @@ module Axlsx
|
|
|
35
37
|
# @option options [String] app_version
|
|
36
38
|
# @option options [Integer] doc_security
|
|
37
39
|
def initialize(options={})
|
|
38
|
-
options
|
|
39
|
-
self.send("#{name}=", value) if self.respond_to? "#{name}="
|
|
40
|
-
end
|
|
40
|
+
parse_options options
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# @return [String] The name of the document template.
|
|
@@ -134,15 +134,15 @@ module Axlsx
|
|
|
134
134
|
|
|
135
135
|
# Sets the template property of your app.xml file
|
|
136
136
|
def template=(v) Axlsx::validate_string v; @template = v; end
|
|
137
|
-
alias :Template :template
|
|
137
|
+
alias :Template= :template=
|
|
138
138
|
|
|
139
139
|
# Sets the manager property of your app.xml file
|
|
140
140
|
def manager=(v) Axlsx::validate_string v; @manager = v; end
|
|
141
|
-
alias :Manager :manager
|
|
141
|
+
alias :Manager= :manager=
|
|
142
142
|
|
|
143
143
|
# Sets the company property of your app.xml file
|
|
144
144
|
def company=(v) Axlsx::validate_string v; @company = v; end
|
|
145
|
-
alias :Company :company
|
|
145
|
+
alias :Company= :company=
|
|
146
146
|
# Sets the pages property of your app.xml file
|
|
147
147
|
def pages=(v) Axlsx::validate_int v; @pages = v; end
|
|
148
148
|
|
|
@@ -223,7 +223,10 @@ module Axlsx
|
|
|
223
223
|
def to_xml_string(str = '')
|
|
224
224
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
|
225
225
|
str << '<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">'
|
|
226
|
-
|
|
226
|
+
instance_values.each do |key, value|
|
|
227
|
+
node_name = Axlsx.camel(key)
|
|
228
|
+
str << "<#{node_name}>#{value}</#{node_name}>"
|
|
229
|
+
end
|
|
227
230
|
str << '</Properties>'
|
|
228
231
|
end
|
|
229
232
|
|
data/lib/axlsx/drawing/axis.rb
CHANGED
|
@@ -4,6 +4,8 @@ module Axlsx
|
|
|
4
4
|
# the access class defines common properties and values for a chart axis.
|
|
5
5
|
class Axis
|
|
6
6
|
|
|
7
|
+
include Axlsx::OptionsParser
|
|
8
|
+
|
|
7
9
|
# Creates an Axis object
|
|
8
10
|
# @param [Integer] ax_id the id of this axis
|
|
9
11
|
# @param [Integer] cross_ax the id of the perpendicular axis
|
|
@@ -25,9 +27,7 @@ module Axlsx
|
|
|
25
27
|
self.format_code = "General"
|
|
26
28
|
self.crosses = :autoZero
|
|
27
29
|
self.gridlines = true
|
|
28
|
-
options
|
|
29
|
-
self.send("#{name}=", value) if self.respond_to? "#{name}="
|
|
30
|
-
end
|
|
30
|
+
parse_options options
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# the fill color to use in the axis shape properties. This should be a 6 character long hex string
|
|
@@ -102,7 +102,7 @@ module Axlsx
|
|
|
102
102
|
|
|
103
103
|
# the position of the tick labels
|
|
104
104
|
# must be one of [:nextTo, :high, :low1]
|
|
105
|
-
def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low], v; @tick_lbl_pos = v; end
|
|
105
|
+
def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low, :none], v; @tick_lbl_pos = v; end
|
|
106
106
|
alias :tickLblPos= :tick_lbl_pos=
|
|
107
107
|
|
|
108
108
|
# The number format format code for this axis
|
data/lib/axlsx/drawing/chart.rb
CHANGED
|
@@ -6,6 +6,7 @@ module Axlsx
|
|
|
6
6
|
# @see README for examples
|
|
7
7
|
class Chart
|
|
8
8
|
|
|
9
|
+
include Axlsx::OptionsParser
|
|
9
10
|
# Creates a new chart object
|
|
10
11
|
# @param [GraphicalFrame] frame The frame that holds this chart.
|
|
11
12
|
# @option options [Cell, String] title
|
|
@@ -21,9 +22,7 @@ module Axlsx
|
|
|
21
22
|
@show_legend = true
|
|
22
23
|
@series_type = Series
|
|
23
24
|
@title = Title.new
|
|
24
|
-
options
|
|
25
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
26
|
-
end
|
|
25
|
+
parse_options options
|
|
27
26
|
start_at(*options[:start_at]) if options[:start_at]
|
|
28
27
|
end_at(*options[:end_at]) if options[:end_at]
|
|
29
28
|
yield self if block_given?
|