ricardoo27-writeexcel 0.6.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitattributes +1 -0
- data/README.rdoc +136 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/charts/chartex.rb +316 -0
- data/charts/demo1.rb +46 -0
- data/charts/demo101.bin +0 -0
- data/charts/demo2.rb +65 -0
- data/charts/demo201.bin +0 -0
- data/charts/demo3.rb +117 -0
- data/charts/demo301.bin +0 -0
- data/charts/demo4.rb +119 -0
- data/charts/demo401.bin +0 -0
- data/charts/demo5.rb +48 -0
- data/charts/demo501.bin +0 -0
- data/examples/a_simple.rb +43 -0
- data/examples/autofilter.rb +265 -0
- data/examples/bigfile.rb +30 -0
- data/examples/chart_area.rb +121 -0
- data/examples/chart_bar.rb +120 -0
- data/examples/chart_column.rb +120 -0
- data/examples/chart_line.rb +120 -0
- data/examples/chart_pie.rb +108 -0
- data/examples/chart_scatter.rb +121 -0
- data/examples/chart_stock.rb +148 -0
- data/examples/chess.rb +142 -0
- data/examples/colors.rb +129 -0
- data/examples/comments1.rb +27 -0
- data/examples/comments2.rb +352 -0
- data/examples/copyformat.rb +52 -0
- data/examples/data_validate.rb +279 -0
- data/examples/date_time.rb +87 -0
- data/examples/defined_name.rb +32 -0
- data/examples/demo.rb +124 -0
- data/examples/diag_border.rb +36 -0
- data/examples/formats.rb +490 -0
- data/examples/formula_result.rb +30 -0
- data/examples/header.rb +137 -0
- data/examples/hide_sheet.rb +29 -0
- data/examples/hyperlink.rb +43 -0
- data/examples/images.rb +63 -0
- data/examples/indent.rb +31 -0
- data/examples/merge1.rb +40 -0
- data/examples/merge2.rb +45 -0
- data/examples/merge3.rb +66 -0
- data/examples/merge4.rb +83 -0
- data/examples/merge5.rb +80 -0
- data/examples/merge6.rb +67 -0
- data/examples/outline.rb +255 -0
- data/examples/outline_collapsed.rb +209 -0
- data/examples/panes.rb +113 -0
- data/examples/password_protection.rb +33 -0
- data/examples/properties.rb +34 -0
- data/examples/properties_jp.rb +33 -0
- data/examples/protection.rb +47 -0
- data/examples/regions.rb +53 -0
- data/examples/repeat.rb +43 -0
- data/examples/republic.png +0 -0
- data/examples/right_to_left.rb +27 -0
- data/examples/row_wrap.rb +53 -0
- data/examples/set_first_sheet.rb +14 -0
- data/examples/stats.rb +74 -0
- data/examples/stocks.rb +81 -0
- data/examples/store_formula.rb +15 -0
- data/examples/tab_colors.rb +31 -0
- data/examples/utf8.rb +15 -0
- data/examples/write_arrays.rb +83 -0
- data/html/en/doc_en.html +5946 -0
- data/html/images/a_simple.jpg +0 -0
- data/html/images/area1.jpg +0 -0
- data/html/images/bar1.jpg +0 -0
- data/html/images/chart_area.xls +0 -0
- data/html/images/column1.jpg +0 -0
- data/html/images/data_validation.jpg +0 -0
- data/html/images/line1.jpg +0 -0
- data/html/images/pie1.jpg +0 -0
- data/html/images/regions.jpg +0 -0
- data/html/images/scatter1.jpg +0 -0
- data/html/images/stats.jpg +0 -0
- data/html/images/stock1.jpg +0 -0
- data/html/images/stocks.jpg +0 -0
- data/html/index.html +16 -0
- data/html/style.css +433 -0
- data/lib/writeexcel.rb +1159 -0
- data/lib/writeexcel/biffwriter.rb +223 -0
- data/lib/writeexcel/caller_info.rb +12 -0
- data/lib/writeexcel/cell_range.rb +332 -0
- data/lib/writeexcel/chart.rb +1968 -0
- data/lib/writeexcel/charts/area.rb +154 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +66 -0
- data/lib/writeexcel/charts/line.rb +154 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +213 -0
- data/lib/writeexcel/col_info.rb +87 -0
- data/lib/writeexcel/colors.rb +68 -0
- data/lib/writeexcel/comments.rb +460 -0
- data/lib/writeexcel/compatibility.rb +65 -0
- data/lib/writeexcel/convert_date_time.rb +117 -0
- data/lib/writeexcel/data_validations.rb +370 -0
- data/lib/writeexcel/debug_info.rb +41 -0
- data/lib/writeexcel/embedded_chart.rb +35 -0
- data/lib/writeexcel/excelformula.y +139 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -0
- data/lib/writeexcel/format.rb +1575 -0
- data/lib/writeexcel/formula.rb +987 -0
- data/lib/writeexcel/helper.rb +78 -0
- data/lib/writeexcel/image.rb +218 -0
- data/lib/writeexcel/olewriter.rb +305 -0
- data/lib/writeexcel/outline.rb +24 -0
- data/lib/writeexcel/properties.rb +242 -0
- data/lib/writeexcel/shared_string_table.rb +153 -0
- data/lib/writeexcel/storage_lite.rb +984 -0
- data/lib/writeexcel/workbook.rb +2478 -0
- data/lib/writeexcel/worksheet.rb +6925 -0
- data/lib/writeexcel/worksheets.rb +25 -0
- data/lib/writeexcel/write_file.rb +63 -0
- 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/helper.rb +31 -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/README +31 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/biff_add_continue_testdata +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/chess.xls +0 -0
- data/test/perl_output/colors.xls +0 -0
- data/test/perl_output/comments0.xls +0 -0
- data/test/perl_output/comments1.xls +0 -0
- data/test/perl_output/comments2.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/defined_name.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/f_font_biff +0 -0
- data/test/perl_output/f_font_key +1 -0
- data/test/perl_output/f_xf_biff +0 -0
- data/test/perl_output/file_font_biff +0 -0
- data/test/perl_output/file_font_key +1 -0
- data/test/perl_output/file_xf_biff +0 -0
- data/test/perl_output/formula_result.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hidden.xls +0 -0
- data/test/perl_output/hide_zero.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/indent.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/merge6.xls +0 -0
- data/test/perl_output/ole_write_header +0 -0
- data/test/perl_output/outline.xls +0 -0
- data/test/perl_output/outline_collapsed.xls +0 -0
- data/test/perl_output/panes.xls +0 -0
- data/test/perl_output/password_protection.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/right_to_left.xls +0 -0
- data/test/perl_output/set_first_sheet.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/store_formula.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/utf8.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/perl_output/ws_colinfo +1 -0
- data/test/perl_output/ws_store_colinfo +0 -0
- data/test/perl_output/ws_store_dimensions +0 -0
- data/test/perl_output/ws_store_filtermode +0 -0
- data/test/perl_output/ws_store_filtermode_off +0 -0
- data/test/perl_output/ws_store_filtermode_on +0 -0
- data/test/perl_output/ws_store_selection +0 -0
- data/test/perl_output/ws_store_window2 +1 -0
- data/test/republic.png +0 -0
- data/test/test_00_IEEE_double.rb +13 -0
- data/test/test_01_add_worksheet.rb +10 -0
- data/test/test_02_merge_formats.rb +49 -0
- data/test/test_04_dimensions.rb +388 -0
- data/test/test_05_rows.rb +175 -0
- data/test/test_06_extsst.rb +74 -0
- data/test/test_11_date_time.rb +475 -0
- data/test/test_12_date_only.rb +525 -0
- data/test/test_13_date_seconds.rb +477 -0
- data/test/test_21_escher.rb +624 -0
- data/test/test_22_mso_drawing_group.rb +741 -0
- data/test/test_23_note.rb +57 -0
- data/test/test_24_txo.rb +74 -0
- data/test/test_25_position_object.rb +80 -0
- data/test/test_26_autofilter.rb +309 -0
- data/test/test_27_autofilter.rb +126 -0
- data/test/test_28_autofilter.rb +156 -0
- data/test/test_29_process_jpg.rb +670 -0
- data/test/test_30_validation_dval.rb +74 -0
- data/test/test_31_validation_dv_strings.rb +123 -0
- data/test/test_32_validation_dv_formula.rb +203 -0
- data/test/test_40_property_types.rb +188 -0
- data/test/test_41_properties.rb +235 -0
- data/test/test_42_set_properties.rb +434 -0
- data/test/test_50_name_stored.rb +295 -0
- data/test/test_51_name_print_area.rb +353 -0
- data/test/test_52_name_print_titles.rb +450 -0
- data/test/test_53_autofilter.rb +199 -0
- data/test/test_60_chart_generic.rb +574 -0
- data/test/test_61_chart_subclasses.rb +84 -0
- data/test/test_62_chart_formats.rb +268 -0
- data/test/test_63_chart_area_formats.rb +645 -0
- data/test/test_biff.rb +71 -0
- data/test/test_big_workbook.rb +17 -0
- data/test/test_compatibility.rb +12 -0
- data/test/test_example_match.rb +3246 -0
- data/test/test_format.rb +1189 -0
- data/test/test_formula.rb +61 -0
- data/test/test_ole.rb +102 -0
- data/test/test_storage_lite.rb +116 -0
- data/test/test_workbook.rb +146 -0
- data/test/test_worksheet.rb +106 -0
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +278 -0
- data/writeexcel.rdoc +1425 -0
- metadata +292 -0
@@ -0,0 +1,154 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Area - A writer class for Excel Area charts.
|
5
|
+
#
|
6
|
+
# Used in conjunction with Chart.
|
7
|
+
#
|
8
|
+
# See formatting note in Chart.
|
9
|
+
#
|
10
|
+
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
|
11
|
+
#
|
12
|
+
# original written in Perl by John McNamara
|
13
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'writeexcel'
|
17
|
+
|
18
|
+
module Writeexcel
|
19
|
+
|
20
|
+
class Chart
|
21
|
+
|
22
|
+
#
|
23
|
+
# ==SYNOPSIS
|
24
|
+
#
|
25
|
+
# To create a simple Excel file with a Area chart using WriteExcel:
|
26
|
+
#
|
27
|
+
# #!/usr/bin/ruby -w
|
28
|
+
#
|
29
|
+
# require 'writeexcel'
|
30
|
+
#
|
31
|
+
# workbook = WriteExcel.new('chart.xls')
|
32
|
+
# worksheet = workbook.add_worksheet
|
33
|
+
#
|
34
|
+
# chart = workbook.add_chart(:type => 'Chart::Area')
|
35
|
+
#
|
36
|
+
# # Configure the chart.
|
37
|
+
# chart.add_series(
|
38
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
39
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
40
|
+
# )
|
41
|
+
#
|
42
|
+
# # Add the worksheet data the chart refers to.
|
43
|
+
# data = [
|
44
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
45
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
46
|
+
# ]
|
47
|
+
#
|
48
|
+
# worksheet.write('A1', data)
|
49
|
+
#
|
50
|
+
# workbook.close
|
51
|
+
#
|
52
|
+
# ==DESCRIPTION
|
53
|
+
#
|
54
|
+
# This module implements Area charts for WriteExcel. The chart object is
|
55
|
+
# created via the Workbook add_chart method:
|
56
|
+
#
|
57
|
+
# chart = workbook.add_chart(:type => 'Chart::Area')
|
58
|
+
#
|
59
|
+
# Once the object is created it can be configured via the following methods
|
60
|
+
# that are common to all chart classes:
|
61
|
+
#
|
62
|
+
# chart.add_series
|
63
|
+
# chart.set_x_axis
|
64
|
+
# chart.set_y_axis
|
65
|
+
# chart.set_title
|
66
|
+
#
|
67
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
68
|
+
# Class specific methods or settings, if any, are explained below.
|
69
|
+
#
|
70
|
+
# ==Area Chart Methods
|
71
|
+
#
|
72
|
+
# There aren't currently any area chart specific methods. See the TODO
|
73
|
+
# section of Chart of Writeexcel.
|
74
|
+
#
|
75
|
+
# ==EXAMPLE
|
76
|
+
#
|
77
|
+
# Here is a complete example that demonstrates most of the available
|
78
|
+
# features when creating a chart.
|
79
|
+
#
|
80
|
+
# #!/usr/bin/ruby -w
|
81
|
+
#
|
82
|
+
# require 'writeexcel'
|
83
|
+
#
|
84
|
+
# workbook = WriteExcel.new('chart_area.xls')
|
85
|
+
# worksheet = workbook.add_worksheet
|
86
|
+
# bold = workbook.add_format(:bold => 1)
|
87
|
+
#
|
88
|
+
# # Add the worksheet data that the charts will refer to.
|
89
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
90
|
+
# data = [
|
91
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
92
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
93
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
94
|
+
# ]
|
95
|
+
#
|
96
|
+
# worksheet.write('A1', headings, bold)
|
97
|
+
# worksheet.write('A2', data)
|
98
|
+
#
|
99
|
+
# # Create a new chart object. In this case an embedded chart.
|
100
|
+
# chart = workbook.add_chart(:type => 'Chart::Area', :embedded => 1)
|
101
|
+
#
|
102
|
+
# # Configure the first series. (Sample 1)
|
103
|
+
# chart.add_series(
|
104
|
+
# :name => 'Sample 1',
|
105
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
106
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
107
|
+
# )
|
108
|
+
#
|
109
|
+
# # Configure the second series. (Sample 2)
|
110
|
+
# chart.add_series(
|
111
|
+
# :name => 'Sample 2',
|
112
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
113
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
114
|
+
# )
|
115
|
+
#
|
116
|
+
# # Add a chart title and some axis labels.
|
117
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
118
|
+
# chart.set_x_axis(:name => 'Test number')
|
119
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
120
|
+
#
|
121
|
+
# # Insert the chart into the worksheet (with an offset).
|
122
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
123
|
+
#
|
124
|
+
# workbook.close
|
125
|
+
#
|
126
|
+
class Area < Chart
|
127
|
+
###############################################################################
|
128
|
+
#
|
129
|
+
# new()
|
130
|
+
#
|
131
|
+
#
|
132
|
+
def initialize(*args) # :nodoc:
|
133
|
+
super
|
134
|
+
end
|
135
|
+
|
136
|
+
###############################################################################
|
137
|
+
#
|
138
|
+
# _store_chart_type()
|
139
|
+
#
|
140
|
+
# Implementation of the abstract method from the specific chart class.
|
141
|
+
#
|
142
|
+
# Write the AREA chart BIFF record. Defines a area chart type.
|
143
|
+
#
|
144
|
+
def store_chart_type # :nodoc:
|
145
|
+
record = 0x101A # Record identifier.
|
146
|
+
length = 0x0002 # Number of bytes to follow.
|
147
|
+
grbit = 0x0001 # Option flags.
|
148
|
+
|
149
|
+
store_simple(record, length, grbit)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end # class Chart
|
153
|
+
|
154
|
+
end # module Writeexcel
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Bar - A writer class for Excel Bar charts.
|
5
|
+
#
|
6
|
+
# Used in conjunction with Chart.
|
7
|
+
#
|
8
|
+
# See formatting note in Chart.
|
9
|
+
#
|
10
|
+
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
|
11
|
+
#
|
12
|
+
# original written in Perl by John McNamara
|
13
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'writeexcel/chart'
|
17
|
+
|
18
|
+
module Writeexcel
|
19
|
+
|
20
|
+
class Chart
|
21
|
+
|
22
|
+
#
|
23
|
+
# ==SYNOPSIS
|
24
|
+
#
|
25
|
+
# To create a simple Excel file with a Bar chart using WriteExcel:
|
26
|
+
#
|
27
|
+
# #!/usr/bin/ruby -w
|
28
|
+
#
|
29
|
+
# require 'writeexcel'
|
30
|
+
#
|
31
|
+
# workbook = WriteExcel.new('chart.xls')
|
32
|
+
# worksheet = workbook.add_worksheet
|
33
|
+
#
|
34
|
+
# chart = workbook.add_chart(:type => 'Chart::Bar')
|
35
|
+
#
|
36
|
+
# # Configure the chart.
|
37
|
+
# chart.add_series(
|
38
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
39
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
40
|
+
# )
|
41
|
+
#
|
42
|
+
# # Add the worksheet data the chart refers to.
|
43
|
+
# data = [
|
44
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
45
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
46
|
+
# ]
|
47
|
+
#
|
48
|
+
# worksheet.write('A1', data)
|
49
|
+
#
|
50
|
+
# workbook.close
|
51
|
+
#
|
52
|
+
# ==DESCRIPTION
|
53
|
+
#
|
54
|
+
# This module implements Bar charts for WriteExcel. The chart object is
|
55
|
+
# created via the Workbook add_chart method:
|
56
|
+
#
|
57
|
+
# chart = workbook.add_chart(:type => 'Chart::Bar')
|
58
|
+
#
|
59
|
+
# Once the object is created it can be configured via the following methods
|
60
|
+
# that are common to all chart classes:
|
61
|
+
#
|
62
|
+
# chart.add_series
|
63
|
+
# chart.set_x_axis
|
64
|
+
# chart.set_y_axis
|
65
|
+
# chart.set_title
|
66
|
+
#
|
67
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
68
|
+
# Class specific methods or settings, if any, are explained below.
|
69
|
+
#
|
70
|
+
# ==Bar Chart Methods
|
71
|
+
#
|
72
|
+
# There aren't currently any bar chart specific methods. See the TODO
|
73
|
+
# section of Chart of Writeexcel.
|
74
|
+
#
|
75
|
+
# ==EXAMPLE
|
76
|
+
#
|
77
|
+
# Here is a complete example that demonstrates most of the available
|
78
|
+
# features when creating a chart.
|
79
|
+
#
|
80
|
+
# #!/usr/bin/ruby -w
|
81
|
+
#
|
82
|
+
# require 'writeexcel'
|
83
|
+
#
|
84
|
+
# workbook = WriteExcel.new('chart_bar.xls')
|
85
|
+
# worksheet = workbook.add_worksheet
|
86
|
+
# bold = workbook.add_format(:bold => 1)
|
87
|
+
#
|
88
|
+
# # Add the worksheet data that the charts will refer to.
|
89
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
90
|
+
# data = [
|
91
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
92
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
93
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
94
|
+
# ]
|
95
|
+
#
|
96
|
+
# worksheet.write('A1', headings, bold)
|
97
|
+
# worksheet.write('A2', data)
|
98
|
+
#
|
99
|
+
# # Create a new chart object. In this case an embedded chart.
|
100
|
+
# chart = workbook.add_chart(:type => 'Chart::Bar', :embedded => 1)
|
101
|
+
#
|
102
|
+
# # Configure the first series. (Sample 1)
|
103
|
+
# chart.add_series(
|
104
|
+
# :name => 'Sample 1',
|
105
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
106
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
107
|
+
# )
|
108
|
+
#
|
109
|
+
# # Configure the second series. (Sample 2)
|
110
|
+
# chart.add_series(
|
111
|
+
# :name => 'Sample 2',
|
112
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
113
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
114
|
+
# )
|
115
|
+
#
|
116
|
+
# # Add a chart title and some axis labels.
|
117
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
118
|
+
# chart.set_x_axis(:name => 'Test number')
|
119
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
120
|
+
#
|
121
|
+
# # Insert the chart into the worksheet (with an offset).
|
122
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
123
|
+
#
|
124
|
+
# workbook.close
|
125
|
+
#
|
126
|
+
class Bar < Chart
|
127
|
+
###############################################################################
|
128
|
+
#
|
129
|
+
# new()
|
130
|
+
#
|
131
|
+
#
|
132
|
+
def initialize(*args) # :nodoc:
|
133
|
+
super
|
134
|
+
@config[:x_axis_text] = [ 0x2D, 0x6D9, 0x5F, 0x1CC, 0x281, 0x0, 90 ]
|
135
|
+
@config[:x_axis_text_pos] = [ 2, 2, 0, 0, 0x17, 0x2A ]
|
136
|
+
@config[:y_axis_text] = [ 0x078A, 0x0DFC, 0x011D, 0x9C, 0x0081, 0x0000 ]
|
137
|
+
@config[:y_axis_text_pos] = [ 2, 2, 0, 0, 0x45, 0x17 ]
|
138
|
+
end
|
139
|
+
|
140
|
+
###############################################################################
|
141
|
+
#
|
142
|
+
# _store_chart_type()
|
143
|
+
#
|
144
|
+
# Implementation of the abstract method from the specific chart class.
|
145
|
+
#
|
146
|
+
# Write the BAR chart BIFF record. Defines a bar or column chart type.
|
147
|
+
#
|
148
|
+
def store_chart_type # :nodoc:
|
149
|
+
record = 0x1017 # Record identifier.
|
150
|
+
length = 0x0006 # Number of bytes to follow.
|
151
|
+
pcOverlap = 0x0000 # Space between bars.
|
152
|
+
pcGap = 0x0096 # Space between cats.
|
153
|
+
grbit = 0x0001 # Option flags.
|
154
|
+
|
155
|
+
store_simple(record, length, pcOverlap, pcGap, grbit)
|
156
|
+
end
|
157
|
+
|
158
|
+
###############################################################################
|
159
|
+
#
|
160
|
+
# _set_embedded_config_data()
|
161
|
+
#
|
162
|
+
# Override some of the default configuration data for an embedded chart.
|
163
|
+
#
|
164
|
+
def set_embedded_config_data # :nodoc:
|
165
|
+
# Set the parent configuration first.
|
166
|
+
super
|
167
|
+
|
168
|
+
# The axis positions are reversed for a bar chart so we change the config.
|
169
|
+
@config[:x_axis_text] = [ 0x57, 0x5BC, 0xB5, 0x214, 0x281, 0x0, 90 ]
|
170
|
+
@config[:x_axis_text_pos] = [ 2, 2, 0, 0, 0x17, 0x2A ]
|
171
|
+
@config[:y_axis_text] = [ 0x074A, 0x0C8F, 0x021F, 0x123, 0x81, 0x0000 ]
|
172
|
+
@config[:y_axis_text_pos] = [ 2, 2, 0, 0, 0x45, 0x17 ]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end # class Chart
|
176
|
+
|
177
|
+
end # module Writeexcel
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Column - A writer class for Excel Column charts.
|
5
|
+
#
|
6
|
+
# Used in conjunction with Chart.
|
7
|
+
#
|
8
|
+
# See formatting note in Chart.
|
9
|
+
#
|
10
|
+
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
|
11
|
+
#
|
12
|
+
# original written in Perl by John McNamara
|
13
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'writeexcel/chart'
|
17
|
+
|
18
|
+
module Writeexcel
|
19
|
+
|
20
|
+
class Chart
|
21
|
+
|
22
|
+
#
|
23
|
+
# ==SYNOPSIS
|
24
|
+
#
|
25
|
+
# To create a simple Excel file with a Column chart using WriteExcel:
|
26
|
+
#
|
27
|
+
# #!/usr/bin/ruby -w
|
28
|
+
#
|
29
|
+
# require 'writeexcel'
|
30
|
+
#
|
31
|
+
# workbook = WriteExcel.new('chart.xls')
|
32
|
+
# worksheet = workbook.add_worksheet
|
33
|
+
#
|
34
|
+
# chart = workbook.add_chart(:type => 'Chart::Column')
|
35
|
+
#
|
36
|
+
# # Configure the chart.
|
37
|
+
# chart.add_series(
|
38
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
39
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
40
|
+
# )
|
41
|
+
#
|
42
|
+
# # Add the worksheet data the chart refers to.
|
43
|
+
# data = [
|
44
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
45
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
46
|
+
# ]
|
47
|
+
#
|
48
|
+
# worksheet.write('A1', data)
|
49
|
+
#
|
50
|
+
# workbook.close
|
51
|
+
#
|
52
|
+
# ==DESCRIPTION
|
53
|
+
#
|
54
|
+
# This module implements Column charts for WriteExcel. The chart object is
|
55
|
+
# created via the Workbook add_chart method:
|
56
|
+
#
|
57
|
+
# chart = workbook.add_chart(:type => 'Chart::Column')
|
58
|
+
#
|
59
|
+
# Once the object is created it can be configured via the following methods
|
60
|
+
# that are common to all chart classes:
|
61
|
+
#
|
62
|
+
# chart.add_series
|
63
|
+
# chart.set_x_axis
|
64
|
+
# chart.set_y_axis
|
65
|
+
# chart.set_title
|
66
|
+
#
|
67
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
68
|
+
# Class specific methods or settings, if any, are explained below.
|
69
|
+
#
|
70
|
+
# ==Column Chart Methods
|
71
|
+
#
|
72
|
+
# There aren't currently any column chart specific methods. See the TODO
|
73
|
+
# section of Chart of Writeexcel.
|
74
|
+
#
|
75
|
+
# ==EXAMPLE
|
76
|
+
#
|
77
|
+
# Here is a complete example that demonstrates most of the available
|
78
|
+
# features when creating a chart.
|
79
|
+
#
|
80
|
+
# #!/usr/bin/ruby -w
|
81
|
+
#
|
82
|
+
# require 'writeexcel'
|
83
|
+
#
|
84
|
+
# workbook = WriteExcel.new('chart_column.xls')
|
85
|
+
# worksheet = workbook.add_worksheet
|
86
|
+
# bold = workbook.add_format(:bold => 1)
|
87
|
+
#
|
88
|
+
# # Add the worksheet data that the charts will refer to.
|
89
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
90
|
+
# data = [
|
91
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
92
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
93
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
94
|
+
# ]
|
95
|
+
#
|
96
|
+
# worksheet.write('A1', headings, bold)
|
97
|
+
# worksheet.write('A2', data)
|
98
|
+
#
|
99
|
+
# # Create a new chart object. In this case an embedded chart.
|
100
|
+
# chart = workbook.add_chart(:type => 'Chart::Column', :embedded => 1)
|
101
|
+
#
|
102
|
+
# # Configure the first series. (Sample 1)
|
103
|
+
# chart.add_series(
|
104
|
+
# :name => 'Sample 1',
|
105
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
106
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
107
|
+
# )
|
108
|
+
#
|
109
|
+
# # Configure the second series. (Sample 2)
|
110
|
+
# chart.add_series(
|
111
|
+
# :name => 'Sample 2',
|
112
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
113
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
114
|
+
# )
|
115
|
+
#
|
116
|
+
# # Add a chart title and some axis labels.
|
117
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
118
|
+
# chart.set_x_axis(:name => 'Test number')
|
119
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
120
|
+
#
|
121
|
+
# # Insert the chart into the worksheet (with an offset).
|
122
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
123
|
+
#
|
124
|
+
# workbook.close
|
125
|
+
#
|
126
|
+
class Column < Chart
|
127
|
+
###############################################################################
|
128
|
+
#
|
129
|
+
# new()
|
130
|
+
#
|
131
|
+
#
|
132
|
+
def initialize(*args) # :nodoc:
|
133
|
+
super(*args)
|
134
|
+
end
|
135
|
+
|
136
|
+
###############################################################################
|
137
|
+
#
|
138
|
+
# _store_chart_type()
|
139
|
+
#
|
140
|
+
# Implementation of the abstract method from the specific chart class.
|
141
|
+
#
|
142
|
+
# Write the BAR chart BIFF record. Defines a bar or column chart type.
|
143
|
+
#
|
144
|
+
def store_chart_type # :nodoc:
|
145
|
+
record = 0x1017 # Record identifier.
|
146
|
+
length = 0x0006 # Number of bytes to follow.
|
147
|
+
pcOverlap = 0x0000 # Space between bars.
|
148
|
+
pcGap = 0x0096 # Space between cats.
|
149
|
+
grbit = 0x0000 # Option flags.
|
150
|
+
|
151
|
+
store_simple(record, length, pcOverlap, pcGap, grbit)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end # class Chart
|
155
|
+
|
156
|
+
end # module Writeexcel
|