Fixed email address to gmail address
[p5sagit/Excel-Template.git] / lib / Excel / Template / Element / Cell.pm_
CommitLineData
d0eafc11 1package Excel::Template::Element::Cell;
2
3use strict;
4
5BEGIN {
6 use vars qw(@ISA);
7 @ISA = qw(Excel::Template::Element);
8
9 use Excel::Template::Element;
10}
11
12sub new
13{
14 my $class = shift;
15 my $self = $class->SUPER::new(@_);
16
17 $self->{TXTOBJ} = Excel::Template::Factory->create('TEXTOBJECT');
18
19 return $self;
20}
21
22sub get_text
23{
24 my $self = shift;
25 my ($context) = @_;
26
27 my $txt = $context->get($self, 'TEXT');
28 if (defined $txt)
29 {
30 my $txt_obj = Excel::Template::Factory->create('TEXTOBJECT');
31 push @{$txt_obj->{STACK}}, $txt;
32 $txt = $txt_obj->resolve($context);
33 }
34 elsif ($self->{TXTOBJ})
35 {
36 $txt = $self->{TXTOBJ}->resolve($context)
37 }
38 else
39 {
a8441e01 40UNI_YES $txt = Unicode::String::utf8('');
41UNI_NO $txt = '';
d0eafc11 42 }
43
44 return $txt;
45}
46
47sub render
48{
49 my $self = shift;
50 my ($context) = @_;
51
52 $context->active_worksheet->write(
53 (map { $context->get($self, $_) } qw(ROW COL)),
54 $self->get_text($context),
55 $context->active_format,
56 );
57
58 return 1;
59}
60
61sub deltas
62{
63 return {
64 COL => +1,
65 };
66}
67
681;
69__END__
70
71=head1 NAME
72
73Excel::Template::Element::Cell - Excel::Template::Element::Cell
74
75=head1 PURPOSE
76
77To actually write stuff to the worksheet
78
79=head1 NODE NAME
80
81CELL
82
83=head1 INHERITANCE
84
85Excel::Template::Element
86
87=head1 ATTRIBUTES
88
89=over 4
90
91=item * TEXT
92
93This is the text to write to the cell. This can either be text or a parameter
94with a dollar-sign in front of the parameter name.
95
96=item * COL
97
98Optionally, you can specify which column you want this cell to be in. It can be
99either a number (zero-based) or an offset. See Excel::Template for more info on
100offset-based numbering.
101
102=back 4
103
104There will be more parameters added, as features are added.
105
106=head1 CHILDREN
107
108Excel::Template::Element::Formula
109
110=head1 EFFECTS
111
112This will consume one column on the current row.
113
114=head1 DEPENDENCIES
115
116None
117
118=head1 USAGE
119
120 <cell text="Some Text Here"/>
121 <cell>Some other text here</cell>
122
123 <cell text="$Param2"/>
124 <cell>Some <var name="Param"> text here</cell>
125
126In the above example, four cells are written out. The first two have text hard-
127coded. The second two have variables. The third and fourth items have another
128thing that should be noted. If you have text where you want a variable in the
129middle, you have to use the latter form. Variables within parameters are the
130entire parameter's value.
131
132Please see Spreadsheet::WriteExcel for what constitutes a legal formula.
133
134=head1 BACK-REFERENCES
135
136Currently, you can only use a hard-coded formula. The next release will add the
137capability to have a formula reference other nodes in the template dynamically.
138
139=head1 AUTHOR
140
c09684ff 141Rob Kinyon (rob.kinyon@gmail.com)
d0eafc11 142
143=head1 SEE ALSO
144
145ROW, VAR, FORMULA
146
147=cut