File: repeat.pl

package info (click to toggle)
libspreadsheet-writeexcel-perl 2.40-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 2,768 kB
  • sloc: perl: 19,617; makefile: 14
file content (46 lines) | stat: -rw-r--r-- 952 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl -w

######################################################################
#
# Example of writing repeated formulas.
#
# reverse(''), August 2002, John McNamara, jmcnamara@cpan.org
#

use strict;
use Spreadsheet::WriteExcel;

my $workbook  = Spreadsheet::WriteExcel->new("repeat.xls");
my $worksheet = $workbook->add_worksheet();


my $limit = 1000;

# Write a column of numbers
for my $row (0..$limit) {
    $worksheet->write($row, 0,  $row);
}


# Store a formula
my $formula = $worksheet->store_formula('=A1*5+4');


# Write a column of formulas based on the stored formula
for my $row (0..$limit) {
    $worksheet->repeat_formula($row, 1, $formula, undef,
                                        qr/^A1$/, 'A'.($row+1));
}


# Direct formula writing. As a speed comparison uncomment the
# following and run the program again

#for my $row (0..$limit) {
#    $worksheet->write_formula($row, 2, '=A'.($row+1).'*5+4');
#}



__END__