writeexcel 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +1 -0
- data/README.rdoc +12 -6
- data/VERSION +1 -1
- data/charts/chartex.rb +316 -315
- data/charts/demo1.rb +1 -0
- data/charts/demo2.rb +1 -0
- data/charts/demo3.rb +117 -116
- data/charts/demo4.rb +119 -118
- data/charts/demo5.rb +48 -47
- data/examples/a_simple.rb +1 -0
- data/examples/autofilter.rb +1 -0
- data/examples/bigfile.rb +30 -29
- data/examples/chart_area.rb +121 -120
- data/examples/chart_bar.rb +120 -119
- data/examples/chart_column.rb +120 -119
- data/examples/chart_line.rb +120 -119
- data/examples/chart_pie.rb +108 -107
- data/examples/chart_scatter.rb +121 -120
- data/examples/chart_stock.rb +148 -147
- data/examples/chess.rb +1 -0
- data/examples/colors.rb +1 -0
- data/examples/comments1.rb +1 -0
- data/examples/comments2.rb +3 -2
- data/examples/copyformat.rb +1 -0
- data/examples/data_validate.rb +1 -0
- data/examples/date_time.rb +1 -0
- data/examples/defined_name.rb +1 -0
- data/examples/demo.rb +1 -0
- data/examples/diag_border.rb +1 -0
- data/examples/formats.rb +1 -0
- data/examples/formula_result.rb +1 -0
- data/examples/header.rb +1 -0
- data/examples/hide_sheet.rb +1 -0
- data/examples/hyperlink.rb +1 -0
- data/examples/images.rb +1 -0
- data/examples/indent.rb +1 -0
- data/examples/merge1.rb +1 -0
- data/examples/merge2.rb +1 -0
- data/examples/merge3.rb +1 -0
- data/examples/merge4.rb +1 -0
- data/examples/merge5.rb +1 -0
- data/examples/merge6.rb +67 -66
- data/examples/outline.rb +1 -0
- data/examples/outline_collapsed.rb +1 -0
- data/examples/panes.rb +1 -0
- data/examples/properties.rb +1 -0
- data/examples/properties_jp.rb +1 -0
- data/examples/protection.rb +1 -0
- data/examples/regions.rb +1 -0
- data/examples/repeat.rb +1 -0
- data/examples/right_to_left.rb +1 -0
- data/examples/row_wrap.rb +1 -0
- data/examples/stats.rb +1 -0
- data/examples/stocks.rb +1 -0
- data/examples/tab_colors.rb +1 -0
- data/examples/write_arrays.rb +1 -0
- data/lib/writeexcel.rb +6 -1
- data/lib/writeexcel/biffwriter.rb +21 -20
- data/lib/writeexcel/chart.rb +25 -12
- data/lib/writeexcel/charts/area.rb +153 -152
- data/lib/writeexcel/charts/bar.rb +178 -177
- data/lib/writeexcel/charts/column.rb +157 -156
- data/lib/writeexcel/charts/external.rb +62 -61
- data/lib/writeexcel/charts/line.rb +153 -152
- data/lib/writeexcel/charts/pie.rb +170 -169
- data/lib/writeexcel/charts/scatter.rb +4 -3
- data/lib/writeexcel/charts/stock.rb +212 -211
- data/lib/writeexcel/compatibility.rb +320 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -586
- data/lib/writeexcel/format.rb +12 -13
- data/lib/writeexcel/formula.rb +30 -28
- data/lib/writeexcel/helper.rb +23 -0
- data/lib/writeexcel/olewriter.rb +5 -16
- data/lib/writeexcel/properties.rb +43 -54
- data/lib/writeexcel/storage_lite.rb +981 -968
- data/lib/writeexcel/workbook.rb +94 -73
- data/lib/writeexcel/worksheet.rb +230 -210
- data/test/helper.rb +19 -0
- data/test/test_00_IEEE_double.rb +1 -0
- data/test/test_01_add_worksheet.rb +1 -0
- data/test/test_02_merge_formats.rb +3 -5
- data/test/test_04_dimensions.rb +3 -5
- data/test/test_05_rows.rb +6 -6
- data/test/test_06_extsst.rb +8 -8
- data/test/test_11_date_time.rb +3 -5
- data/test/test_12_date_only.rb +3 -5
- data/test/test_13_date_seconds.rb +4 -6
- data/test/test_21_escher.rb +3 -5
- data/test/test_22_mso_drawing_group.rb +20 -22
- data/test/test_23_note.rb +5 -7
- data/test/test_24_txo.rb +3 -5
- data/test/test_25_position_object.rb +84 -79
- data/test/test_26_autofilter.rb +3 -13
- data/test/test_27_autofilter.rb +3 -13
- data/test/test_28_autofilter.rb +3 -13
- data/test/test_29_process_jpg.rb +5 -0
- data/test/test_30_validation_dval.rb +3 -5
- data/test/test_31_validation_dv_strings.rb +3 -5
- data/test/test_32_validation_dv_formula.rb +3 -5
- data/test/test_40_property_types.rb +10 -9
- data/test/test_41_properties.rb +1 -0
- data/test/test_42_set_properties.rb +14 -15
- data/test/test_50_name_stored.rb +299 -302
- data/test/test_51_name_print_area.rb +357 -360
- data/test/test_52_name_print_titles.rb +454 -457
- data/test/test_53_autofilter.rb +203 -206
- data/test/test_60_chart_generic.rb +5 -0
- data/test/test_61_chart_subclasses.rb +95 -94
- data/test/test_62_chart_formats.rb +272 -267
- data/test/test_63_chart_area_formats.rb +649 -644
- data/test/test_biff.rb +12 -38
- data/test/test_compatibility.rb +627 -0
- data/test/test_example_match.rb +3 -18
- data/test/test_format.rb +46 -105
- data/test/test_formula.rb +1 -0
- data/test/test_ole.rb +3 -4
- data/test/test_storage_lite.rb +125 -146
- data/test/test_workbook.rb +2 -23
- data/test/test_worksheet.rb +4 -5
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +8 -2
- metadata +10 -4
@@ -1,156 +1,157 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# chart.
|
35
|
-
#
|
36
|
-
# :
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# data
|
41
|
-
#
|
42
|
-
# [ '
|
43
|
-
# ]
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# chart.
|
61
|
-
# chart.
|
62
|
-
# chart.
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# [
|
90
|
-
# [
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
# worksheet.write('
|
95
|
-
#
|
96
|
-
#
|
97
|
-
# chart
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
# :
|
103
|
-
# :
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
# :
|
110
|
-
# :
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
# chart
|
115
|
-
# chart.
|
116
|
-
# chart.
|
117
|
-
#
|
118
|
-
#
|
119
|
-
# worksheet
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
data
|
151
|
-
data += [
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
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
|
+
class Chart
|
19
|
+
|
20
|
+
#
|
21
|
+
# ==SYNOPSIS
|
22
|
+
#
|
23
|
+
# To create a simple Excel file with a Column chart using WriteExcel:
|
24
|
+
#
|
25
|
+
# #!/usr/bin/ruby -w
|
26
|
+
#
|
27
|
+
# require 'writeexcel'
|
28
|
+
#
|
29
|
+
# workbook = WriteExcel.new('chart.xls')
|
30
|
+
# worksheet = workbook.add_worksheet
|
31
|
+
#
|
32
|
+
# chart = workbook.add_chart(:type => Chart::Column)
|
33
|
+
#
|
34
|
+
# # Configure the chart.
|
35
|
+
# chart.add_series(
|
36
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
37
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
38
|
+
# )
|
39
|
+
#
|
40
|
+
# # Add the worksheet data the chart refers to.
|
41
|
+
# data = [
|
42
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
43
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
44
|
+
# ]
|
45
|
+
#
|
46
|
+
# worksheet.write('A1', data)
|
47
|
+
#
|
48
|
+
# workbook.close
|
49
|
+
#
|
50
|
+
# ==DESCRIPTION
|
51
|
+
#
|
52
|
+
# This module implements Column charts for WriteExcel. The chart object is
|
53
|
+
# created via the Workbook add_chart method:
|
54
|
+
#
|
55
|
+
# chart = workbook.add_chart(:type => Chart::Column)
|
56
|
+
#
|
57
|
+
# Once the object is created it can be configured via the following methods
|
58
|
+
# that are common to all chart classes:
|
59
|
+
#
|
60
|
+
# chart.add_series
|
61
|
+
# chart.set_x_axis
|
62
|
+
# chart.set_y_axis
|
63
|
+
# chart.set_title
|
64
|
+
#
|
65
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
66
|
+
# Class specific methods or settings, if any, are explained below.
|
67
|
+
#
|
68
|
+
# ==Column Chart Methods
|
69
|
+
#
|
70
|
+
# There aren't currently any column chart specific methods. See the TODO
|
71
|
+
# section of Chart of Writeexcel.
|
72
|
+
#
|
73
|
+
# ==EXAMPLE
|
74
|
+
#
|
75
|
+
# Here is a complete example that demonstrates most of the available
|
76
|
+
# features when creating a chart.
|
77
|
+
#
|
78
|
+
# #!/usr/bin/ruby -w
|
79
|
+
#
|
80
|
+
# require 'writeexcel'
|
81
|
+
#
|
82
|
+
# workbook = WriteExcel.new('chart_column.xls')
|
83
|
+
# worksheet = workbook.add_worksheet
|
84
|
+
# bold = workbook.add_format(:bold => 1)
|
85
|
+
#
|
86
|
+
# # Add the worksheet data that the charts will refer to.
|
87
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
88
|
+
# data = [
|
89
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
90
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
91
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
92
|
+
# ]
|
93
|
+
#
|
94
|
+
# worksheet.write('A1', headings, bold)
|
95
|
+
# worksheet.write('A2', data)
|
96
|
+
#
|
97
|
+
# # Create a new chart object. In this case an embedded chart.
|
98
|
+
# chart = workbook.add_chart(:type => Chart::Column, :embedded => 1)
|
99
|
+
#
|
100
|
+
# # Configure the first series. (Sample 1)
|
101
|
+
# chart.add_series(
|
102
|
+
# :name => 'Sample 1',
|
103
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
104
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
105
|
+
# )
|
106
|
+
#
|
107
|
+
# # Configure the second series. (Sample 2)
|
108
|
+
# chart.add_series(
|
109
|
+
# :name => 'Sample 2',
|
110
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
111
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
112
|
+
# )
|
113
|
+
#
|
114
|
+
# # Add a chart title and some axis labels.
|
115
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
116
|
+
# chart.set_x_axis(:name => 'Test number')
|
117
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
118
|
+
#
|
119
|
+
# # Insert the chart into the worksheet (with an offset).
|
120
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
121
|
+
#
|
122
|
+
# workbook.close
|
123
|
+
#
|
124
|
+
class Column < Chart
|
125
|
+
###############################################################################
|
126
|
+
#
|
127
|
+
# new()
|
128
|
+
#
|
129
|
+
#
|
130
|
+
def initialize(*args) # :nodoc:
|
131
|
+
super(*args)
|
132
|
+
end
|
133
|
+
|
134
|
+
###############################################################################
|
135
|
+
#
|
136
|
+
# _store_chart_type()
|
137
|
+
#
|
138
|
+
# Implementation of the abstract method from the specific chart class.
|
139
|
+
#
|
140
|
+
# Write the BAR chart BIFF record. Defines a bar or column chart type.
|
141
|
+
#
|
142
|
+
def store_chart_type # :nodoc:
|
143
|
+
record = 0x1017 # Record identifier.
|
144
|
+
length = 0x0006 # Number of bytes to follow.
|
145
|
+
pcOverlap = 0x0000 # Space between bars.
|
146
|
+
pcGap = 0x0096 # Space between cats.
|
147
|
+
grbit = 0x0000 # Option flags.
|
148
|
+
|
149
|
+
header = [record, length].pack('vv')
|
150
|
+
data = [pcOverlap].pack('v')
|
151
|
+
data += [pcGap].pack('v')
|
152
|
+
data += [grbit].pack('v')
|
153
|
+
|
154
|
+
append(header, data)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -1,61 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@
|
44
|
-
@
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
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
|
+
class External < Chart # :nodoc:
|
19
|
+
###############################################################################
|
20
|
+
#
|
21
|
+
# new()
|
22
|
+
#
|
23
|
+
def initialize(external_filename, *args)
|
24
|
+
super(*args)
|
25
|
+
|
26
|
+
@filename = external_filename
|
27
|
+
@external_bin = true
|
28
|
+
|
29
|
+
_initialize # Requires overridden initialize().
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
###############################################################################
|
34
|
+
#
|
35
|
+
# _initialize()
|
36
|
+
#
|
37
|
+
# Read all the data into memory for the external binary style chart.
|
38
|
+
#
|
39
|
+
def _initialize
|
40
|
+
filename = @filename
|
41
|
+
filehandle = File.open(filename, 'rb')
|
42
|
+
|
43
|
+
@filehandle = filehandle
|
44
|
+
@datasize = FileTest.size(filename)
|
45
|
+
@using_tmpfile = false
|
46
|
+
|
47
|
+
# Read the entire external chart binary into the the data buffer.
|
48
|
+
# This will be retrieved by _get_data() when the chart is closed().
|
49
|
+
@data = @filehandle.read(@datasize)
|
50
|
+
end
|
51
|
+
|
52
|
+
###############################################################################
|
53
|
+
#
|
54
|
+
# _close()
|
55
|
+
#
|
56
|
+
# We don't need to create or store Chart data structures when using an
|
57
|
+
# external binary, so we have a default close method.
|
58
|
+
#
|
59
|
+
def close
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
@@ -1,152 +1,153 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# chart.
|
35
|
-
#
|
36
|
-
# :
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# data
|
41
|
-
#
|
42
|
-
# [ '
|
43
|
-
# ]
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# chart.
|
61
|
-
# chart.
|
62
|
-
# chart.
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# [
|
90
|
-
# [
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
# worksheet.write('
|
95
|
-
#
|
96
|
-
#
|
97
|
-
# chart
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
# :
|
103
|
-
# :
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
# :
|
110
|
-
# :
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
# chart
|
115
|
-
# chart.
|
116
|
-
# chart.
|
117
|
-
#
|
118
|
-
#
|
119
|
-
# worksheet
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
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
|
+
class Chart
|
19
|
+
|
20
|
+
#
|
21
|
+
# ==SYNOPSIS
|
22
|
+
#
|
23
|
+
# To create a simple Excel file with a Line chart using WriteExcel:
|
24
|
+
#
|
25
|
+
# #!/usr/bin/ruby -w
|
26
|
+
#
|
27
|
+
# require 'writeexcel'
|
28
|
+
#
|
29
|
+
# workbook = WriteExcel.new('chart.xls')
|
30
|
+
# worksheet = workbook.add_worksheet
|
31
|
+
#
|
32
|
+
# chart = workbook.add_chart(:type => Chart::Line)
|
33
|
+
#
|
34
|
+
# # Configure the chart.
|
35
|
+
# chart.add_series(
|
36
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
37
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
38
|
+
# )
|
39
|
+
#
|
40
|
+
# # Add the worksheet data the chart refers to.
|
41
|
+
# data = [
|
42
|
+
# [ 'Category', 2, 3, 4, 5, 6, 7 ],
|
43
|
+
# [ 'Value', 1, 4, 5, 2, 1, 5 ]
|
44
|
+
# ]
|
45
|
+
#
|
46
|
+
# worksheet.write('A1', data)
|
47
|
+
#
|
48
|
+
# workbook.close
|
49
|
+
#
|
50
|
+
# ==DESCRIPTION
|
51
|
+
#
|
52
|
+
# This module implements Line charts for WriteExcel. The chart object is
|
53
|
+
# created via the Workbook add_chart method:
|
54
|
+
#
|
55
|
+
# chart = workbook.add_chart(:type => Chart::Line)
|
56
|
+
#
|
57
|
+
# Once the object is created it can be configured via the following methods
|
58
|
+
# that are common to all chart classes:
|
59
|
+
#
|
60
|
+
# chart.add_series
|
61
|
+
# chart.set_x_axis
|
62
|
+
# chart.set_y_axis
|
63
|
+
# chart.set_title
|
64
|
+
#
|
65
|
+
# These methods are explained in detail in Chart section of WriteExcel.
|
66
|
+
# Class specific methods or settings, if any, are explained below.
|
67
|
+
#
|
68
|
+
# ==Line Chart Methods
|
69
|
+
#
|
70
|
+
# There aren't currently any Line chart specific methods. See the TODO
|
71
|
+
# section of Chart of Writeexcel.
|
72
|
+
#
|
73
|
+
# ==EXAMPLE
|
74
|
+
#
|
75
|
+
# Here is a complete example that demonstrates most of the available
|
76
|
+
# features when creating a chart.
|
77
|
+
#
|
78
|
+
# #!/usr/bin/ruby -w
|
79
|
+
#
|
80
|
+
# require 'writeexcel'
|
81
|
+
#
|
82
|
+
# workbook = WriteExcel.new('chart_line.xls')
|
83
|
+
# worksheet = workbook.add_worksheet
|
84
|
+
# bold = workbook.add_format(:bold => 1)
|
85
|
+
#
|
86
|
+
# # Add the worksheet data that the charts will refer to.
|
87
|
+
# headings = [ 'Number', 'Sample 1', 'Sample 2' ]
|
88
|
+
# data = [
|
89
|
+
# [ 2, 3, 4, 5, 6, 7 ],
|
90
|
+
# [ 1, 4, 5, 2, 1, 5 ],
|
91
|
+
# [ 3, 6, 7, 5, 4, 3 ]
|
92
|
+
# ]
|
93
|
+
#
|
94
|
+
# worksheet.write('A1', headings, bold)
|
95
|
+
# worksheet.write('A2', data)
|
96
|
+
#
|
97
|
+
# # Create a new chart object. In this case an embedded chart.
|
98
|
+
# chart = workbook.add_chart(:type => Chart::Line, :embedded => 1)
|
99
|
+
#
|
100
|
+
# # Configure the first series. (Sample 1)
|
101
|
+
# chart.add_series(
|
102
|
+
# :name => 'Sample 1',
|
103
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
104
|
+
# :values => '=Sheet1!$B$2:$B$7',
|
105
|
+
# )
|
106
|
+
#
|
107
|
+
# # Configure the second series. (Sample 2)
|
108
|
+
# chart.add_series(
|
109
|
+
# :name => 'Sample 2',
|
110
|
+
# :categories => '=Sheet1!$A$2:$A$7',
|
111
|
+
# :values => '=Sheet1!$C$2:$C$7',
|
112
|
+
# )
|
113
|
+
#
|
114
|
+
# # Add a chart title and some axis labels.
|
115
|
+
# chart.set_title (:name => 'Results of sample analysis')
|
116
|
+
# chart.set_x_axis(:name => 'Test number')
|
117
|
+
# chart.set_y_axis(:name => 'Sample length (cm)')
|
118
|
+
#
|
119
|
+
# # Insert the chart into the worksheet (with an offset).
|
120
|
+
# worksheet.insert_chart('D2', chart, 25, 10)
|
121
|
+
#
|
122
|
+
# workbook.close
|
123
|
+
#
|
124
|
+
class Line < Chart
|
125
|
+
###############################################################################
|
126
|
+
#
|
127
|
+
# new()
|
128
|
+
#
|
129
|
+
#
|
130
|
+
def initialize(*args) # :nodoc:
|
131
|
+
super(*args)
|
132
|
+
end
|
133
|
+
|
134
|
+
###############################################################################
|
135
|
+
#
|
136
|
+
# _store_chart_type()
|
137
|
+
#
|
138
|
+
# Implementation of the abstract method from the specific chart class.
|
139
|
+
#
|
140
|
+
# Write the LINE chart BIFF record. Defines a line chart type.
|
141
|
+
#
|
142
|
+
def store_chart_type # :nodoc:
|
143
|
+
record = 0x1018 # Record identifier.
|
144
|
+
length = 0x0002 # Number of bytes to follow.
|
145
|
+
grbit = 0x0000 # Option flags.
|
146
|
+
|
147
|
+
header = [record, length].pack('vv')
|
148
|
+
data = [grbit].pack('v')
|
149
|
+
|
150
|
+
append(header, data)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|