forked from jmcnamara/spreadsheet-writeexcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo2.pl
65 lines (48 loc) · 1.82 KB
/
demo2.pl
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
62
63
64
65
#!/usr/bin/perl -w
###############################################################################
#
# Simple example of how to add an externally created chart to a Spreadsheet::
# WriteExcel file.
#
#
# This example adds a pie chart extracted from the file Chart2.xls as follows:
#
# perl chartex.pl -c=demo2 Chart2.xls
#
#
# reverse('©'), September 2004, John McNamara, jmcnamara@cpan.org
#
use strict;
use Spreadsheet::WriteExcel;
my $workbook = Spreadsheet::WriteExcel->new("demo2.xls");
my $worksheet = $workbook->add_worksheet();
# Add the chart extracted using the chartex utility
my $chart = $workbook->add_chart_ext('demo201.bin', 'Chart1');
# Link the chart to the worksheet data using a dummy formula.
$worksheet->store_formula('=Sheet1!A1');
# Add some extra formats to cover formats used in the charts.
my $chart_font_1 = $workbook->add_format(font_only => 1);
my $chart_font_2 = $workbook->add_format(font_only => 1);
my $chart_font_3 = $workbook->add_format(font_only => 1);
my $chart_font_4 = $workbook->add_format(font_only => 1);
my $chart_font_5 = $workbook->add_format(font_only => 1);
# Add all other formats.
my $bold = $workbook->add_format(bold => 1);
# Adjust column widths and add some headers
$worksheet->set_column('A:B', 20);
$worksheet->write('A1', 'Module', $bold);
$worksheet->write('B1', 'No. of lines', $bold);
# Add data to range that the chart refers to.
my @data = (
['BIFFwriter.pm', 275],
['Big.pm', 99],
['Chart.pm', 269],
['Format.pm', 724],
['Formula.pm', 1410],
['OLEwriter.pm', 447],
['Utility.pm', 884],
['Workbook.pm', 1925],
['WorkbookBig.pm', 112],
['Worksheet.pm', 3945],
);
$worksheet->write_col('A2', \@data);