Commit | Line | Data |
37513eae |
1 | package Excel::Template::Element::Range; |
2 | |
3 | use strict; |
4 | use Spreadsheet::WriteExcel::Utility; |
5 | |
6 | BEGIN { |
7 | use vars qw(@ISA); |
8 | @ISA = qw(Excel::Template::Element); |
9 | |
10 | use Excel::Template::Element; |
11 | } |
12 | |
13 | sub min { $_[0] < $_[1] ? $_[0] : $_[1] } |
14 | sub max { $_[0] > $_[1] ? $_[0] : $_[1] } |
15 | |
16 | sub 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 | |
44 | 1; |
45 | __END__ |
46 | |
47 | =head1 NAME |
48 | |
49 | Excel::Template::Element::Range |
50 | |
51 | =head1 PURPOSE |
52 | |
b6bc5a5d |
53 | Returns a range of cell locations (i.e. B2:C2) that contains all calls using |
54 | this reference. To return the location of the last cell, use BACKREF. |
37513eae |
55 | |
56 | =head1 NODE NAME |
57 | |
b6bc5a5d |
58 | RANGE |
37513eae |
59 | |
60 | =head1 INHERITANCE |
61 | |
62 | Excel::Template::Element |
63 | |
64 | =head1 ATTRIBUTES |
65 | |
66 | =over 4 |
67 | |
68 | =item * REF |
69 | |
70 | This is the name of the reference to look up. |
71 | |
6dd4c89d |
72 | =back |
37513eae |
73 | |
74 | =head1 CHILDREN |
75 | |
76 | None |
77 | |
78 | =head1 EFFECTS |
79 | |
80 | None |
81 | |
82 | =head1 DEPENDENCIES |
83 | |
84 | This will only be used within CELL tags. |
85 | |
86 | =head1 USAGE |
87 | |
88 | In 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 | |
97 | The formula in row 2 would be =SUM(B1:C1). |
98 | |
99 | =head1 AUTHOR |
100 | |
101 | Rob Kinyon (rkinyon@columbus.rr.com) |
102 | |
103 | =head1 SEE ALSO |
104 | |
b6bc5a5d |
105 | CELL, BACKREF |
37513eae |
106 | |
107 | =cut |