r13925@rob-kinyons-powerbook58: rob | 2006-06-02 14:29:05 -0400
[p5sagit/Excel-Template.git] / lib / Excel / Template / Element / Range.pm
CommitLineData
37513eae 1package Excel::Template::Element::Range;
2
3use strict;
4use Spreadsheet::WriteExcel::Utility;
5
6BEGIN {
7 use vars qw(@ISA);
8 @ISA = qw(Excel::Template::Element);
9
10 use Excel::Template::Element;
11}
12
13sub min { $_[0] < $_[1] ? $_[0] : $_[1] }
14sub max { $_[0] > $_[1] ? $_[0] : $_[1] }
15
16sub resolve
17{
18 my $self = shift;
19 my ($context) = @_;
20
21 my $ref_name = $context->resolve($self, 'REF');
22
23 my @refs = $context->get_all_references( $ref_name );
24 return '' unless @refs;
25
26 my ($top, $left, $bottom, $right) =
27 ( $refs[0][0], $refs[0][1] ) x 2;
28
29 shift @refs;
30 foreach my $ref ( @refs )
31 {
32 $top = min( $top, $ref->[0]);
33 $bottom = max( $bottom, $ref->[0]);
34 $left = min( $left, $ref->[1]);
35 $right = max( $right, $ref->[1]);
36 }
37
38 return join( ':',
39 xl_rowcol_to_cell($top, $left),
40 xl_rowcol_to_cell($bottom, $right)
41 );
42}
43
441;
45__END__
46
47=head1 NAME
48
49Excel::Template::Element::Range
50
51=head1 PURPOSE
52
b6bc5a5d 53Returns a range of cell locations (i.e. B2:C2) that contains all calls using
54this reference. To return the location of the last cell, use BACKREF.
37513eae 55
56=head1 NODE NAME
57
b6bc5a5d 58RANGE
37513eae 59
60=head1 INHERITANCE
61
62Excel::Template::Element
63
64=head1 ATTRIBUTES
65
66=over 4
67
68=item * REF
69
70This is the name of the reference to look up.
71
6dd4c89d 72=back
37513eae 73
74=head1 CHILDREN
75
76None
77
78=head1 EFFECTS
79
80None
81
82=head1 DEPENDENCIES
83
84This will only be used within CELL tags.
85
86=head1 USAGE
87
88In the example...
89
90 <row>
91 <cell ref="this_cell"/><cell ref="that_cell"><cell ref="that_cell">
92 </row>
93 <row>
94 <formula>=SUM(<range ref="that_cell">)</formula>
95 </row>
96
97The formula in row 2 would be =SUM(B1:C1).
98
99=head1 AUTHOR
100
101Rob Kinyon (rkinyon@columbus.rr.com)
102
103=head1 SEE ALSO
104
b6bc5a5d 105CELL, BACKREF
37513eae 106
107=cut