3
###############################################################################
5
# Simple example of how to add an externally created chart to a Spreadsheet::
9
# This example adds an "Open-high-low-close" stock chart extracted from the
10
# file Chart3.xls as follows:
12
# perl chartex.pl -c=demo3 Chart3.xls
14
# reverse('�'), September 2004, John McNamara, jmcnamara@cpan.org
18
use Spreadsheet::WriteExcel;
20
my $workbook = Spreadsheet::WriteExcel->new("demo3.xls");
21
my $worksheet = $workbook->add_worksheet();
24
# Add the chart extracted using the chartex utility
25
my $chart = $workbook->add_chart_ext('demo301.bin', 'Chart1');
28
# Link the chart to the worksheet data using a dummy formula.
29
$worksheet->store_formula('=Sheet1!A1');
32
# Add some extra formats to cover formats used in the charts.
33
$workbook->add_format(color => 1);
34
$workbook->add_format(color => 2);
35
$workbook->add_format(color => 3, bold => 1);
36
$workbook->add_format(color => 4);
39
# Add all other formats.
40
my $bold = $workbook->add_format(bold => 1);
41
my $date_format = $workbook->add_format(num_format => 'dd/mm/yyyy');
44
# Adjust column widths and add some headers
45
$worksheet->set_column('A:A', 12);
47
$worksheet->write('A1', 'Date', $bold);
48
$worksheet->write('B1', 'Open', $bold);
49
$worksheet->write('C1', 'High', $bold);
50
$worksheet->write('D1', 'Low', $bold);
51
$worksheet->write('E1', 'Close', $bold);
54
# Add data to range that the chart refers to.
82
# Open-High-Low-Close prices
85
[100.00, 104.06, 95.96, 100.34],
86
[101.01, 109.08, 100.50, 108.31],
87
[110.75, 113.48, 109.05, 109.40],
88
[111.24, 111.60, 103.57, 104.87],
89
[104.96, 108.00, 103.88, 106.00],
90
[104.95, 107.95, 104.66, 107.91],
91
[108.10, 108.62, 105.69, 106.15],
92
[105.28, 105.49, 102.01, 102.01],
93
[102.30, 103.71, 102.16, 102.37],
94
[102.70, 102.97, 99.67, 100.25],
95
[ 99.19, 102.37, 98.94, 101.51],
96
[100.95, 101.74, 99.32, 100.01],
97
[101.01, 102.00, 99.61, 101.58],
98
[100.74, 103.03, 100.50, 102.30],
99
[102.53, 102.71, 101.00, 102.31],
100
[101.60, 106.56, 101.30, 105.33],
101
[106.63, 108.41, 106.46, 107.50],
102
[107.45, 112.00, 106.79, 111.49],
103
[110.56, 114.23, 110.20, 112.00],
104
[112.34, 115.80, 111.65, 113.97],
105
[114.42, 117.49, 113.55, 117.49],
106
[116.95, 121.60, 116.77, 119.36],
107
[119.81, 120.42, 117.51, 117.84],
113
$worksheet->write_date_time($row++, 0, $_, $date_format) for @dates;
114
$worksheet->write_col('B2', \@prices);