094326e478c8f72ab3738d7b8d0134c20ced180a
[p5sagit/Excel-Template.git] / lib / Excel / Template / Element / Formula.pm
1 package Excel::Template::Element::Formula;
2
3 use strict;
4
5 BEGIN {
6     use vars qw(@ISA);
7     @ISA = qw(Excel::Template::Element::Cell);
8
9     use Excel::Template::Element::Cell;
10 }
11
12 sub get_text
13 {
14     my $self = shift;
15     my ($context) = @_;
16
17     my $text = $self->SUPER::get_text($context);
18
19 # At this point, we must do back-reference dereferencing
20
21     return $text;
22 }
23
24 sub render
25 {
26     my $self = shift;
27     my ($context) = @_;
28
29     $context->active_worksheet->write_formula(
30         (map { $context->get($self, $_) } qw(ROW COL)),
31         $self->get_text($context),
32     );
33
34     return 1;
35 }
36
37 1;
38 __END__
39
40 =head1 NAME
41
42 Excel::Template::Element::Formula - Excel::Template::Element::Formula
43
44 =head1 PURPOSE
45
46 To write formulas to the worksheet
47
48 =head1 NODE NAME
49
50 FORMULA
51
52 =head1 INHERITANCE
53
54 Excel::Template::Element::Cell
55
56 =head1 ATTRIBUTES
57
58 =over 4
59
60 =item * TEXT
61
62 This is the formula to write to the cell. This can either be text or a parameter
63 with a dollar-sign in front of the parameter name.
64
65 =item * COL
66
67 Optionally, you can specify which column you want this cell to be in. It can be
68 either a number (zero-based) or an offset. See Excel::Template for more info on
69 offset-based numbering.
70
71 =back 4
72
73 There will be more parameters added, as features are added.
74
75 =head1 CHILDREN
76
77 None
78
79 =head1 EFFECTS
80
81 This will consume one column on the current row. 
82
83 =head1 DEPENDENCIES
84
85 None
86
87 =head1 USAGE
88
89   <formula text="=(1 + 2)"/>
90   <formula>=SUM(A1:A5)</formula>
91
92   <formula text="$Param2"/>
93   <formula>=(A1 + <var name="Param">)</formula>
94
95 In the above example, four formulas are written out. The first two have the
96 formula hard-coded. The second two have variables. The third and fourth items
97 have another thing that should be noted. If you have a formula where you want a
98 variable in the middle, you have to use the latter form. Variables within
99 parameters are the entire parameter's value.
100
101 =head1 AUTHOR
102
103 Rob Kinyon (rkinyon@columbus.rr.com)
104
105 =head1 SEE ALSO
106
107 ROW, VAR, CELL
108
109 =cut