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,66 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# External - A writer class for Excel external charts.
|
5
|
+
#
|
6
|
+
# Used in conjunction with WriteExcel
|
7
|
+
#
|
8
|
+
# perltidy with options: -mbl=2 -pt=0 -nola
|
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 External < Chart # :nodoc:
|
21
|
+
###############################################################################
|
22
|
+
#
|
23
|
+
# new()
|
24
|
+
#
|
25
|
+
def initialize(external_filename, *args)
|
26
|
+
super(*args)
|
27
|
+
|
28
|
+
@filename = external_filename
|
29
|
+
@external_bin = true
|
30
|
+
|
31
|
+
_initialize # Requires overridden initialize().
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
###############################################################################
|
36
|
+
#
|
37
|
+
# _initialize()
|
38
|
+
#
|
39
|
+
# Read all the data into memory for the external binary style chart.
|
40
|
+
#
|
41
|
+
def _initialize
|
42
|
+
filename = @filename
|
43
|
+
filehandle = File.open(filename, 'rb')
|
44
|
+
|
45
|
+
@filehandle = filehandle
|
46
|
+
@datasize = FileTest.size(filename)
|
47
|
+
@using_tmpfile = false
|
48
|
+
|
49
|
+
# Read the entire external chart binary into the the data buffer.
|
50
|
+
# This will be retrieved by _get_data() when the chart is closed().
|
51
|
+
@data = @filehandle.read(@datasize)
|
52
|
+
end
|
53
|
+
|
54
|
+
###############################################################################
|
55
|
+
#
|
56
|
+
# _close()
|
57
|
+
#
|
58
|
+
# We don't need to create or store Chart data structures when using an
|
59
|
+
# external binary, so we have a default close method.
|
60
|
+
#
|
61
|
+
def close
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end # class Chart
|
65
|
+
|
66
|
+
end # module Writeexcel
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Line - A writer class for Excel Line 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 Line 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::Line')
|
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 Line charts for WriteExcel. The chart object is
|
55
|
+
# created via the Workbook add_chart method:
|
56
|
+
#
|
57
|
+
# chart = workbook.add_chart(:type => 'Chart::Line')
|
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
|
+
# ==Line Chart Methods
|
71
|
+
#
|
72
|
+
# There aren't currently any Line 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_line.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::Line', :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 Line < 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 LINE chart BIFF record. Defines a line chart type.
|
143
|
+
#
|
144
|
+
def store_chart_type # :nodoc:
|
145
|
+
record = 0x1018 # Record identifier.
|
146
|
+
length = 0x0002 # Number of bytes to follow.
|
147
|
+
grbit = 0x0000 # 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,169 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Pie - A writer class for Excel Pie charts.
|
5
|
+
#
|
6
|
+
# Used in conjunction with WriteExcel::Chart.
|
7
|
+
#
|
8
|
+
# See formatting note in WriteExcel::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
|
+
# ==SYNOPSIS
|
23
|
+
#
|
24
|
+
# To create a simple Excel file with a Pie chart using WriteExcel:
|
25
|
+
#
|
26
|
+
# #!/usr/bin/ruby -w
|
27
|
+
#
|
28
|
+
# require 'writeexcel'
|
29
|
+
#
|
30
|
+
# workbook = WriteExcel.new('chart.xls')
|
31
|
+
# worksheet = workbook.add_worksheet
|
32
|
+
#
|
33
|
+
# chart = workbook.add_chart(:type => 'Chart::Pie')
|
34
|
+
#
|
35
|
+
# # Configure the chart.
|
36
|
+
# chart.add_series(
|
37
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
38
|
+
# :values => '=Sheet1!$B$2:$B$7'
|
39
|
+
# )
|
40
|
+
#
|
41
|
+
# # Add the worksheet data the chart refers to.
|
42
|
+
# data = [
|
43
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
44
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
45
|
+
# ]
|
46
|
+
#
|
47
|
+
# worksheet.write('A1', data)
|
48
|
+
#
|
49
|
+
# workbook.close
|
50
|
+
#
|
51
|
+
# ==DESCRIPTION
|
52
|
+
#
|
53
|
+
# This module implements Pie charts for WriteExcel. The chart
|
54
|
+
# object is created via the Workbook add_chart() method:
|
55
|
+
#
|
56
|
+
# chart = workbook.add_chart(:type => 'Chart::Pie')
|
57
|
+
#
|
58
|
+
# Once the object is created it can be configured via the following methods
|
59
|
+
# that are common to all chart classes:
|
60
|
+
#
|
61
|
+
# chart.add_series
|
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
|
+
# ==Pie Chart Methods
|
68
|
+
#
|
69
|
+
# There aren't currently any pie chart specific methods. See the TODO
|
70
|
+
# section of Chart section in WriteExcel.
|
71
|
+
#
|
72
|
+
# A Pie chart doesn't have an X or Y axis so the following common chart
|
73
|
+
# methods are ignored.
|
74
|
+
#
|
75
|
+
# chart.set_x_axis
|
76
|
+
# chart.set_y_axis
|
77
|
+
#
|
78
|
+
# ==EXAMPLE
|
79
|
+
#
|
80
|
+
# Here is a complete example that demonstrates most of the available
|
81
|
+
# features when creating a chart.
|
82
|
+
#
|
83
|
+
# #!/usr/bin/ruby -w
|
84
|
+
#
|
85
|
+
# require 'writeexcel'
|
86
|
+
#
|
87
|
+
# workbook = WriteExcel.new('chart_pie.xls')
|
88
|
+
# worksheet = workbook.add_worksheet
|
89
|
+
# bold = workbook.add_format(:bold => 1)
|
90
|
+
#
|
91
|
+
# # Add the worksheet data that the charts will refer to.
|
92
|
+
# headings = [ 'Category', 'Values' ]
|
93
|
+
# data = [
|
94
|
+
# [ 'Apple', 'Cherry', 'Pecan' ],
|
95
|
+
# [ 60, 30, 10 ],
|
96
|
+
# ]
|
97
|
+
#
|
98
|
+
# worksheet.write('A1', headings, bold)
|
99
|
+
# worksheet.write('A2', data)
|
100
|
+
#
|
101
|
+
# # Create a new chart object. In this case an embedded chart.
|
102
|
+
# chart = workbook.add_chart(:type => 'Chart::Pie', :embedded => 1)
|
103
|
+
#
|
104
|
+
# # Configure the series.
|
105
|
+
# chart.add_series(
|
106
|
+
# :name => 'Pie sales data',
|
107
|
+
# :categories => '=Sheet1!$A$2:$A$4',
|
108
|
+
# :values => '=Sheet1!$B$2:$B$4',
|
109
|
+
# )
|
110
|
+
#
|
111
|
+
# # Add a title.
|
112
|
+
# chart.set_title(:name => 'Popular Pie Types')
|
113
|
+
#
|
114
|
+
#
|
115
|
+
# # Insert the chart into the worksheet (with an offset).
|
116
|
+
# worksheet.insert_chart('C2', chart, 25, 10)
|
117
|
+
#
|
118
|
+
# workbook.close
|
119
|
+
#
|
120
|
+
class Pie < Chart
|
121
|
+
###############################################################################
|
122
|
+
#
|
123
|
+
# new()
|
124
|
+
#
|
125
|
+
#
|
126
|
+
def initialize(*args) # :nodoc:
|
127
|
+
super
|
128
|
+
@vary_data_color = 1
|
129
|
+
end
|
130
|
+
|
131
|
+
###############################################################################
|
132
|
+
#
|
133
|
+
# _store_chart_type()
|
134
|
+
#
|
135
|
+
# Implementation of the abstract method from the specific chart class.
|
136
|
+
#
|
137
|
+
# Write the Pie chart BIFF record.
|
138
|
+
#
|
139
|
+
def store_chart_type # :nodoc:
|
140
|
+
record = 0x1019 # Record identifier.
|
141
|
+
length = 0x0006 # Number of bytes to follow.
|
142
|
+
angle = 0x0000 # Angle.
|
143
|
+
donut = 0x0000 # Donut hole size.
|
144
|
+
grbit = 0x0002 # Option flags.
|
145
|
+
|
146
|
+
store_simple(record, length, angle, donut, grbit)
|
147
|
+
end
|
148
|
+
|
149
|
+
###############################################################################
|
150
|
+
#
|
151
|
+
# _store_axisparent_stream(). Overridden.
|
152
|
+
#
|
153
|
+
# Write the AXISPARENT chart substream.
|
154
|
+
#
|
155
|
+
# A Pie chart has no X or Y axis so we override this method to remove them.
|
156
|
+
#
|
157
|
+
def store_axisparent_stream # :nodoc:
|
158
|
+
store_axisparent(*@config[:axisparent])
|
159
|
+
|
160
|
+
store_begin
|
161
|
+
store_pos(*@config[:axisparent_pos])
|
162
|
+
|
163
|
+
store_chartformat_stream
|
164
|
+
store_end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end # class Chart
|
168
|
+
|
169
|
+
end # module Writeexcel
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Scatter - A writer class for Excel Scatter charts.
|
5
|
+
#
|
6
|
+
# Used in conjunction with WriteExcel::Chart.
|
7
|
+
#
|
8
|
+
# See formatting note in WriteExcel::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
|
+
# ==SYNOPSIS
|
23
|
+
#
|
24
|
+
# To create a simple Excel file with a Scatter chart using WriteExcel:
|
25
|
+
#
|
26
|
+
# #!/usr/bin/ruby -w
|
27
|
+
#
|
28
|
+
# require 'writeexcel'
|
29
|
+
#
|
30
|
+
# workbook = WriteExcel.new('chart.xls')
|
31
|
+
# worksheet = workbook.add_worksheet
|
32
|
+
#
|
33
|
+
# chart = workbook.add_chart(:type => 'Chart::Scatter')
|
34
|
+
#
|
35
|
+
# # Configure the chart.
|
36
|
+
# chart.add_series(
|
37
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
38
|
+
# :values => '=Sheet1!$B$2:$B$7'
|
39
|
+
# )
|
40
|
+
#
|
41
|
+
# # Add the worksheet data the chart refers to.
|
42
|
+
# data = [
|
43
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
44
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
45
|
+
# ]
|
46
|
+
#
|
47
|
+
# worksheet.write('A1', data)
|
48
|
+
#
|
49
|
+
# workbook.close
|
50
|
+
#
|
51
|
+
# ==DESCRIPTION
|
52
|
+
#
|
53
|
+
# This module implements Scatter charts for WriteExcel.
|
54
|
+
# The chart object is created via the Workbook add_chart() method:
|
55
|
+
#
|
56
|
+
# chart = workbook.add_chart(:type => 'Chart::Scatter')
|
57
|
+
#
|
58
|
+
# Once the object is created it can be configured via the following
|
59
|
+
# methods that are common to all chart classes:
|
60
|
+
#
|
61
|
+
# chart.add_series
|
62
|
+
# chart.set_x_axis
|
63
|
+
# chart.set_y_axis
|
64
|
+
# chart.set_title
|
65
|
+
#
|
66
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
67
|
+
# Class specific methods or settings, if any, are explained below.
|
68
|
+
#
|
69
|
+
# ==Scatter Chart Methods
|
70
|
+
#
|
71
|
+
# There aren't currently any scatter chart specific methods. See the TODO
|
72
|
+
# section of Chart section in WriteExcel.
|
73
|
+
#
|
74
|
+
# ==EXAMPLE
|
75
|
+
#
|
76
|
+
# Here is a complete example that demonstrates most of the available
|
77
|
+
# features when creating a chart.
|
78
|
+
#
|
79
|
+
# #!/usr/bin/ruby -w
|
80
|
+
#
|
81
|
+
# require 'writeexcel'
|
82
|
+
#
|
83
|
+
# workbook = WriteExcel.new('chart_scatter.xls')
|
84
|
+
# worksheet = workbook.add_worksheet
|
85
|
+
# bold = workbook.add_format(:bold => 1)
|
86
|
+
#
|
87
|
+
# # Add the worksheet data that the charts will refer to.
|
88
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
89
|
+
# data = [
|
90
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
91
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
92
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
93
|
+
# ]
|
94
|
+
#
|
95
|
+
# worksheet.write('A1', headings, bold)
|
96
|
+
# worksheet.write('A2', data)
|
97
|
+
#
|
98
|
+
# # Create a new chart object. In this case an embedded chart.
|
99
|
+
# chart = workbook.add_chart(:type => 'Chart::Scatter', :embedded => 1)
|
100
|
+
#
|
101
|
+
# # Configure the first series. (Sample 1)
|
102
|
+
# chart.add_series(
|
103
|
+
# :name => 'Sample 1',
|
104
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
105
|
+
# :values => '=Sheet1!$B$2:$B$7'
|
106
|
+
# )
|
107
|
+
#
|
108
|
+
# # Configure the second series. (Sample 2)
|
109
|
+
# chart.add_series(
|
110
|
+
# :name => 'Sample 2',
|
111
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
112
|
+
# :values => '=Sheet1!$C$2:$C$7'
|
113
|
+
# )
|
114
|
+
#
|
115
|
+
# # Add a chart title and some axis labels.
|
116
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
117
|
+
# chart.set_x_axis(:name => 'Test number')
|
118
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
119
|
+
#
|
120
|
+
# # Insert the chart into the worksheet (with an offset).
|
121
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
122
|
+
#
|
123
|
+
# workbook.close
|
124
|
+
#
|
125
|
+
class Scatter < Chart
|
126
|
+
###############################################################################
|
127
|
+
#
|
128
|
+
# new()
|
129
|
+
#
|
130
|
+
#
|
131
|
+
def initialize(*args) # :nodoc:
|
132
|
+
super
|
133
|
+
end
|
134
|
+
|
135
|
+
###############################################################################
|
136
|
+
#
|
137
|
+
# _store_chart_type()
|
138
|
+
#
|
139
|
+
# Implementation of the abstract method from the specific chart class.
|
140
|
+
#
|
141
|
+
# Write the AREA chart BIFF record. Defines a area chart type.
|
142
|
+
#
|
143
|
+
def store_chart_type # :nodoc:
|
144
|
+
record = 0x101B # Record identifier.
|
145
|
+
length = 0x0006 # Number of bytes to follow.
|
146
|
+
bubble_ratio = 0x0064 # Bubble ratio.
|
147
|
+
bubble_type = 0x0001 # Bubble type.
|
148
|
+
grbit = 0x0000 # Option flags.
|
149
|
+
|
150
|
+
store_simple(record, length, bubble_ratio, bubble_type, grbit)
|
151
|
+
end
|
152
|
+
|
153
|
+
###############################################################################
|
154
|
+
#
|
155
|
+
# _store_axis_category_stream(). Overridden.
|
156
|
+
#
|
157
|
+
# Write the AXIS chart substream for the chart category.
|
158
|
+
#
|
159
|
+
# For a Scatter chart the category stream is replace with a values stream. We
|
160
|
+
# override this method and turn it into a values stream.
|
161
|
+
#
|
162
|
+
def store_axis_category_stream # :nodoc:
|
163
|
+
store_axis(0)
|
164
|
+
|
165
|
+
store_begin
|
166
|
+
store_valuerange
|
167
|
+
store_tick
|
168
|
+
store_end
|
169
|
+
end
|
170
|
+
|
171
|
+
###############################################################################
|
172
|
+
#
|
173
|
+
# _store_marker_dataformat_stream(). Overridden.
|
174
|
+
#
|
175
|
+
# This is an implementation of the parent abstract method to define
|
176
|
+
# properties of markers, linetypes, pie formats and other.
|
177
|
+
#
|
178
|
+
def store_marker_dataformat_stream # :nodoc:
|
179
|
+
store_dataformat(0x0000, 0xFFFD, 0x0000)
|
180
|
+
|
181
|
+
store_begin
|
182
|
+
store_3dbarshape
|
183
|
+
store_lineformat(0x00000000, 0x0005, 0xFFFF, 0x0008, 0x004D)
|
184
|
+
store_areaformat(0x00FFFFFF, 0x0000, 0x01, 0x01, 0x4E, 0x4D)
|
185
|
+
store_pieformat
|
186
|
+
store_markerformat(0x00, 0x00, 0x02, 0x01, 0x4D, 0x4D, 0x3C)
|
187
|
+
store_end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end # class Chart
|
191
|
+
|
192
|
+
end # module Writeexcel
|