writeexcel 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
@@ -0,0 +1,152 @@
|
|
1
|
+
###############################################################################
|
2
|
+
#
|
3
|
+
# Area - A writer class for Excel Area charts.
|
4
|
+
#
|
5
|
+
# Used in conjunction with Chart.
|
6
|
+
#
|
7
|
+
# See formatting note in Chart.
|
8
|
+
#
|
9
|
+
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
|
10
|
+
#
|
11
|
+
# original written in Perl by John McNamara
|
12
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'writeexcel'
|
16
|
+
|
17
|
+
class Chart
|
18
|
+
|
19
|
+
#
|
20
|
+
# ==SYNOPSIS
|
21
|
+
#
|
22
|
+
# To create a simple Excel file with a Area chart using WriteExcel:
|
23
|
+
#
|
24
|
+
# #!/usr/bin/ruby -w
|
25
|
+
#
|
26
|
+
# require 'writeexcel'
|
27
|
+
#
|
28
|
+
# workbook = WriteExcel.new('chart.xls')
|
29
|
+
# worksheet = workbook.add_worksheet
|
30
|
+
#
|
31
|
+
# chart = workbook.add_chart(:type => Chart::Area)
|
32
|
+
#
|
33
|
+
# # Configure the chart.
|
34
|
+
# chart.add_series(
|
35
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
36
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
37
|
+
# )
|
38
|
+
#
|
39
|
+
# # Add the worksheet data the chart refers to.
|
40
|
+
# data = [
|
41
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
42
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
43
|
+
# ]
|
44
|
+
#
|
45
|
+
# worksheet.write('A1', data)
|
46
|
+
#
|
47
|
+
# workbook.close
|
48
|
+
#
|
49
|
+
# ==DESCRIPTION
|
50
|
+
#
|
51
|
+
# This module implements Area charts for WriteExcel. The chart object is
|
52
|
+
# created via the Workbook add_chart method:
|
53
|
+
#
|
54
|
+
# chart = workbook.add_chart(:type => Chart::Area)
|
55
|
+
#
|
56
|
+
# Once the object is created it can be configured via the following methods
|
57
|
+
# that are common to all chart classes:
|
58
|
+
#
|
59
|
+
# chart.add_series
|
60
|
+
# chart.set_x_axis
|
61
|
+
# chart.set_y_axis
|
62
|
+
# chart.set_title
|
63
|
+
#
|
64
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
65
|
+
# Class specific methods or settings, if any, are explained below.
|
66
|
+
#
|
67
|
+
# ==Area Chart Methods
|
68
|
+
#
|
69
|
+
# There aren't currently any area chart specific methods. See the TODO
|
70
|
+
# section of Chart of Writeexcel.
|
71
|
+
#
|
72
|
+
# ==EXAMPLE
|
73
|
+
#
|
74
|
+
# Here is a complete example that demonstrates most of the available
|
75
|
+
# features when creating a chart.
|
76
|
+
#
|
77
|
+
# #!/usr/bin/ruby -w
|
78
|
+
#
|
79
|
+
# require 'writeexcel'
|
80
|
+
#
|
81
|
+
# workbook = WriteExcel.new('chart_area.xls')
|
82
|
+
# worksheet = workbook.add_worksheet
|
83
|
+
# bold = workbook.add_format(:bold => 1)
|
84
|
+
#
|
85
|
+
# # Add the worksheet data that the charts will refer to.
|
86
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
87
|
+
# data = [
|
88
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
89
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
90
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
91
|
+
# ]
|
92
|
+
#
|
93
|
+
# worksheet.write('A1', headings, bold)
|
94
|
+
# worksheet.write('A2', data)
|
95
|
+
#
|
96
|
+
# # Create a new chart object. In this case an embedded chart.
|
97
|
+
# chart = workbook.add_chart(:type => Chart::Area, :embedded => 1)
|
98
|
+
#
|
99
|
+
# # Configure the first series. (Sample 1)
|
100
|
+
# chart.add_series(
|
101
|
+
# :name => 'Sample 1',
|
102
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
103
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
104
|
+
# )
|
105
|
+
#
|
106
|
+
# # Configure the second series. (Sample 2)
|
107
|
+
# chart.add_series(
|
108
|
+
# :name => 'Sample 2',
|
109
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
110
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
111
|
+
# )
|
112
|
+
#
|
113
|
+
# # Add a chart title and some axis labels.
|
114
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
115
|
+
# chart.set_x_axis(:name => 'Test number')
|
116
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
117
|
+
#
|
118
|
+
# # Insert the chart into the worksheet (with an offset).
|
119
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
120
|
+
#
|
121
|
+
# workbook.close
|
122
|
+
#
|
123
|
+
class Area < Chart
|
124
|
+
###############################################################################
|
125
|
+
#
|
126
|
+
# new()
|
127
|
+
#
|
128
|
+
#
|
129
|
+
def initialize(*args) # :nodoc:
|
130
|
+
super
|
131
|
+
end
|
132
|
+
|
133
|
+
###############################################################################
|
134
|
+
#
|
135
|
+
# _store_chart_type()
|
136
|
+
#
|
137
|
+
# Implementation of the abstract method from the specific chart class.
|
138
|
+
#
|
139
|
+
# Write the AREA chart BIFF record. Defines a area chart type.
|
140
|
+
#
|
141
|
+
def store_chart_type # :nodoc:
|
142
|
+
record = 0x101A # Record identifier.
|
143
|
+
length = 0x0002 # Number of bytes to follow.
|
144
|
+
grbit = 0x0001 # Option flags.
|
145
|
+
|
146
|
+
header = [record, length].pack('vv')
|
147
|
+
data = [grbit].pack('v')
|
148
|
+
|
149
|
+
append(header, data)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
###############################################################################
|
2
|
+
#
|
3
|
+
# Bar - A writer class for Excel Bar charts.
|
4
|
+
#
|
5
|
+
# Used in conjunction with Chart.
|
6
|
+
#
|
7
|
+
# See formatting note in Chart.
|
8
|
+
#
|
9
|
+
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
|
10
|
+
#
|
11
|
+
# original written in Perl by John McNamara
|
12
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'writeexcel/chart'
|
16
|
+
|
17
|
+
class Chart
|
18
|
+
|
19
|
+
#
|
20
|
+
# ==SYNOPSIS
|
21
|
+
#
|
22
|
+
# To create a simple Excel file with a Bar chart using WriteExcel:
|
23
|
+
#
|
24
|
+
# #!/usr/bin/ruby -w
|
25
|
+
#
|
26
|
+
# require 'writeexcel'
|
27
|
+
#
|
28
|
+
# workbook = WriteExcel.new('chart.xls')
|
29
|
+
# worksheet = workbook.add_worksheet
|
30
|
+
#
|
31
|
+
# chart = workbook.add_chart(:type => Chart::Bar)
|
32
|
+
#
|
33
|
+
# # Configure the chart.
|
34
|
+
# chart.add_series(
|
35
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
36
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
37
|
+
# )
|
38
|
+
#
|
39
|
+
# # Add the worksheet data the chart refers to.
|
40
|
+
# data = [
|
41
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
42
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
43
|
+
# ]
|
44
|
+
#
|
45
|
+
# worksheet.write('A1', data)
|
46
|
+
#
|
47
|
+
# workbook.close
|
48
|
+
#
|
49
|
+
# ==DESCRIPTION
|
50
|
+
#
|
51
|
+
# This module implements Bar charts for WriteExcel. The chart object is
|
52
|
+
# created via the Workbook add_chart method:
|
53
|
+
#
|
54
|
+
# chart = workbook.add_chart(:type => Chart::Bar)
|
55
|
+
#
|
56
|
+
# Once the object is created it can be configured via the following methods
|
57
|
+
# that are common to all chart classes:
|
58
|
+
#
|
59
|
+
# chart.add_series
|
60
|
+
# chart.set_x_axis
|
61
|
+
# chart.set_y_axis
|
62
|
+
# chart.set_title
|
63
|
+
#
|
64
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
65
|
+
# Class specific methods or settings, if any, are explained below.
|
66
|
+
#
|
67
|
+
# ==Bar Chart Methods
|
68
|
+
#
|
69
|
+
# There aren't currently any bar chart specific methods. See the TODO
|
70
|
+
# section of Chart of Writeexcel.
|
71
|
+
#
|
72
|
+
# ==EXAMPLE
|
73
|
+
#
|
74
|
+
# Here is a complete example that demonstrates most of the available
|
75
|
+
# features when creating a chart.
|
76
|
+
#
|
77
|
+
# #!/usr/bin/ruby -w
|
78
|
+
#
|
79
|
+
# require 'writeexcel'
|
80
|
+
#
|
81
|
+
# workbook = WriteExcel.new('chart_bar.xls')
|
82
|
+
# worksheet = workbook.add_worksheet
|
83
|
+
# bold = workbook.add_format(:bold => 1)
|
84
|
+
#
|
85
|
+
# # Add the worksheet data that the charts will refer to.
|
86
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
87
|
+
# data = [
|
88
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
89
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
90
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
91
|
+
# ]
|
92
|
+
#
|
93
|
+
# worksheet.write('A1', headings, bold)
|
94
|
+
# worksheet.write('A2', data)
|
95
|
+
#
|
96
|
+
# # Create a new chart object. In this case an embedded chart.
|
97
|
+
# chart = workbook.add_chart(:type => Chart::Bar, :embedded => 1)
|
98
|
+
#
|
99
|
+
# # Configure the first series. (Sample 1)
|
100
|
+
# chart.add_series(
|
101
|
+
# :name => 'Sample 1',
|
102
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
103
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
104
|
+
# )
|
105
|
+
#
|
106
|
+
# # Configure the second series. (Sample 2)
|
107
|
+
# chart.add_series(
|
108
|
+
# :name => 'Sample 2',
|
109
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
110
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
111
|
+
# )
|
112
|
+
#
|
113
|
+
# # Add a chart title and some axis labels.
|
114
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
115
|
+
# chart.set_x_axis(:name => 'Test number')
|
116
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
117
|
+
#
|
118
|
+
# # Insert the chart into the worksheet (with an offset).
|
119
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
120
|
+
#
|
121
|
+
# workbook.close
|
122
|
+
#
|
123
|
+
class Bar < Chart
|
124
|
+
###############################################################################
|
125
|
+
#
|
126
|
+
# new()
|
127
|
+
#
|
128
|
+
#
|
129
|
+
def initialize(*args) # :nodoc:
|
130
|
+
super
|
131
|
+
@config[:x_axis_text] = [ 0x2D, 0x6D9, 0x5F, 0x1CC, 0x281, 0x0, 90 ]
|
132
|
+
@config[:x_axis_text_pos] = [ 2, 2, 0, 0, 0x17, 0x2A ]
|
133
|
+
@config[:y_axis_text] = [ 0x078A, 0x0DFC, 0x011D, 0x9C, 0x0081, 0x0000 ]
|
134
|
+
@config[:y_axis_text_pos] = [ 2, 2, 0, 0, 0x45, 0x17 ]
|
135
|
+
end
|
136
|
+
|
137
|
+
###############################################################################
|
138
|
+
#
|
139
|
+
# _store_chart_type()
|
140
|
+
#
|
141
|
+
# Implementation of the abstract method from the specific chart class.
|
142
|
+
#
|
143
|
+
# Write the BAR chart BIFF record. Defines a bar or column chart type.
|
144
|
+
#
|
145
|
+
def store_chart_type # :nodoc:
|
146
|
+
record = 0x1017 # Record identifier.
|
147
|
+
length = 0x0006 # Number of bytes to follow.
|
148
|
+
pcOverlap = 0x0000 # Space between bars.
|
149
|
+
pcGap = 0x0096 # Space between cats.
|
150
|
+
grbit = 0x0001 # Option flags.
|
151
|
+
|
152
|
+
header = [record, length].pack('vv')
|
153
|
+
data = [pcOverlap].pack('v')
|
154
|
+
data += [pcGap].pack('v')
|
155
|
+
data += [grbit].pack('v')
|
156
|
+
|
157
|
+
append(header, data)
|
158
|
+
end
|
159
|
+
|
160
|
+
###############################################################################
|
161
|
+
#
|
162
|
+
# _set_embedded_config_data()
|
163
|
+
#
|
164
|
+
# Override some of the default configuration data for an embedded chart.
|
165
|
+
#
|
166
|
+
def set_embedded_config_data # :nodoc:
|
167
|
+
# Set the parent configuration first.
|
168
|
+
super
|
169
|
+
|
170
|
+
# The axis positions are reversed for a bar chart so we change the config.
|
171
|
+
@config[:x_axis_text] = [ 0x57, 0x5BC, 0xB5, 0x214, 0x281, 0x0, 90 ]
|
172
|
+
@config[:x_axis_text_pos] = [ 2, 2, 0, 0, 0x17, 0x2A ]
|
173
|
+
@config[:y_axis_text] = [ 0x074A, 0x0C8F, 0x021F, 0x123, 0x81, 0x0000 ]
|
174
|
+
@config[:y_axis_text_pos] = [ 2, 2, 0, 0, 0x45, 0x17 ]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
###############################################################################
|
2
|
+
#
|
3
|
+
# Column - A writer class for Excel Column charts.
|
4
|
+
#
|
5
|
+
# Used in conjunction with Chart.
|
6
|
+
#
|
7
|
+
# See formatting note in Chart.
|
8
|
+
#
|
9
|
+
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
|
10
|
+
#
|
11
|
+
# original written in Perl by John McNamara
|
12
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'writeexcel/chart'
|
16
|
+
|
17
|
+
class Chart
|
18
|
+
|
19
|
+
#
|
20
|
+
# ==SYNOPSIS
|
21
|
+
#
|
22
|
+
# To create a simple Excel file with a Column chart using WriteExcel:
|
23
|
+
#
|
24
|
+
# #!/usr/bin/ruby -w
|
25
|
+
#
|
26
|
+
# require 'writeexcel'
|
27
|
+
#
|
28
|
+
# workbook = WriteExcel.new('chart.xls')
|
29
|
+
# worksheet = workbook.add_worksheet
|
30
|
+
#
|
31
|
+
# chart = workbook.add_chart(:type => Chart::Column)
|
32
|
+
#
|
33
|
+
# # Configure the chart.
|
34
|
+
# chart.add_series(
|
35
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
36
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
37
|
+
# )
|
38
|
+
#
|
39
|
+
# # Add the worksheet data the chart refers to.
|
40
|
+
# data = [
|
41
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
42
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
43
|
+
# ]
|
44
|
+
#
|
45
|
+
# worksheet.write('A1', data)
|
46
|
+
#
|
47
|
+
# workbook.close
|
48
|
+
#
|
49
|
+
# ==DESCRIPTION
|
50
|
+
#
|
51
|
+
# This module implements Column charts for WriteExcel. The chart object is
|
52
|
+
# created via the Workbook add_chart method:
|
53
|
+
#
|
54
|
+
# chart = workbook.add_chart(:type => Chart::Column)
|
55
|
+
#
|
56
|
+
# Once the object is created it can be configured via the following methods
|
57
|
+
# that are common to all chart classes:
|
58
|
+
#
|
59
|
+
# chart.add_series
|
60
|
+
# chart.set_x_axis
|
61
|
+
# chart.set_y_axis
|
62
|
+
# chart.set_title
|
63
|
+
#
|
64
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
65
|
+
# Class specific methods or settings, if any, are explained below.
|
66
|
+
#
|
67
|
+
# ==Column Chart Methods
|
68
|
+
#
|
69
|
+
# There aren't currently any column chart specific methods. See the TODO
|
70
|
+
# section of Chart of Writeexcel.
|
71
|
+
#
|
72
|
+
# ==EXAMPLE
|
73
|
+
#
|
74
|
+
# Here is a complete example that demonstrates most of the available
|
75
|
+
# features when creating a chart.
|
76
|
+
#
|
77
|
+
# #!/usr/bin/ruby -w
|
78
|
+
#
|
79
|
+
# require 'writeexcel'
|
80
|
+
#
|
81
|
+
# workbook = WriteExcel.new('chart_column.xls')
|
82
|
+
# worksheet = workbook.add_worksheet
|
83
|
+
# bold = workbook.add_format(:bold => 1)
|
84
|
+
#
|
85
|
+
# # Add the worksheet data that the charts will refer to.
|
86
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
87
|
+
# data = [
|
88
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
89
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
90
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
91
|
+
# ]
|
92
|
+
#
|
93
|
+
# worksheet.write('A1', headings, bold)
|
94
|
+
# worksheet.write('A2', data)
|
95
|
+
#
|
96
|
+
# # Create a new chart object. In this case an embedded chart.
|
97
|
+
# chart = workbook.add_chart(:type => Chart::Column, :embedded => 1)
|
98
|
+
#
|
99
|
+
# # Configure the first series. (Sample 1)
|
100
|
+
# chart.add_series(
|
101
|
+
# :name => 'Sample 1',
|
102
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
103
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
104
|
+
# )
|
105
|
+
#
|
106
|
+
# # Configure the second series. (Sample 2)
|
107
|
+
# chart.add_series(
|
108
|
+
# :name => 'Sample 2',
|
109
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
110
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
111
|
+
# )
|
112
|
+
#
|
113
|
+
# # Add a chart title and some axis labels.
|
114
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
115
|
+
# chart.set_x_axis(:name => 'Test number')
|
116
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
117
|
+
#
|
118
|
+
# # Insert the chart into the worksheet (with an offset).
|
119
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
120
|
+
#
|
121
|
+
# workbook.close
|
122
|
+
#
|
123
|
+
class Column < Chart
|
124
|
+
###############################################################################
|
125
|
+
#
|
126
|
+
# new()
|
127
|
+
#
|
128
|
+
#
|
129
|
+
def initialize(*args) # :nodoc:
|
130
|
+
super(*args)
|
131
|
+
end
|
132
|
+
|
133
|
+
###############################################################################
|
134
|
+
#
|
135
|
+
# _store_chart_type()
|
136
|
+
#
|
137
|
+
# Implementation of the abstract method from the specific chart class.
|
138
|
+
#
|
139
|
+
# Write the BAR chart BIFF record. Defines a bar or column chart type.
|
140
|
+
#
|
141
|
+
def store_chart_type # :nodoc:
|
142
|
+
record = 0x1017 # Record identifier.
|
143
|
+
length = 0x0006 # Number of bytes to follow.
|
144
|
+
pcOverlap = 0x0000 # Space between bars.
|
145
|
+
pcGap = 0x0096 # Space between cats.
|
146
|
+
grbit = 0x0000 # Option flags.
|
147
|
+
|
148
|
+
header = [record, length].pack('vv')
|
149
|
+
data = [pcOverlap].pack('v')
|
150
|
+
data += [pcGap].pack('v')
|
151
|
+
data += [grbit].pack('v')
|
152
|
+
|
153
|
+
append(header, data)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|