Fixed minor installation and documentation issues
[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;
b6bc5a5d 50 my ($context, $method) = @_;
51
52 $method ||= 'write';
d0eafc11 53
37513eae 54 my ($row, $col) = map { $context->get($self, $_) } qw(ROW COL);
55
56 my $ref = uc $context->get( $self, 'REF' );
57 if (defined $ref && length $ref)
58 {
59 $context->add_reference( $ref, $row, $col );
60 }
61
dee1f239 62 # Apply the cell width to the current column
63 if (my $width = $context->get($self, 'WIDTH'))
64 {
65 $width =~ s/\D//g;
66 $width *= 1;
67 if ($width > 0)
68 {
69 $context->active_worksheet->set_column($col, $col, $width);
70 }
71 }
72
b6bc5a5d 73 $context->active_worksheet->$method(
37513eae 74 $row, $col,
d0eafc11 75 $self->get_text($context),
76 $context->active_format,
77 );
78
79 return 1;
80}
81
82sub deltas
83{
84 return {
85 COL => +1,
86 };
87}
88
891;
90__END__
91
92=head1 NAME
93
94Excel::Template::Element::Cell - Excel::Template::Element::Cell
95
96=head1 PURPOSE
97
98To actually write stuff to the worksheet
99
100=head1 NODE NAME
101
102CELL
103
104=head1 INHERITANCE
105
106Excel::Template::Element
107
108=head1 ATTRIBUTES
109
110=over 4
111
112=item * TEXT
113
114This is the text to write to the cell. This can either be text or a parameter
115with a dollar-sign in front of the parameter name.
116
117=item * COL
118
119Optionally, you can specify which column you want this cell to be in. It can be
120either a number (zero-based) or an offset. See Excel::Template for more info on
121offset-based numbering.
122
b6bc5a5d 123=item * REF
124
125Adds the current cell to the a list of cells that can be backreferenced.
126This is useful when the current cell needs to be referenced by a
127formula. See BACKREF and RANGE.
128
dee1f239 129=item * WIDTH
130
131Sets the width of the column the cell is in. The last setting for a given column
132will win out.
133
d0eafc11 134=back 4
135
136There will be more parameters added, as features are added.
137
138=head1 CHILDREN
139
140Excel::Template::Element::Formula
141
142=head1 EFFECTS
143
144This will consume one column on the current row.
145
146=head1 DEPENDENCIES
147
148None
149
150=head1 USAGE
151
152 <cell text="Some Text Here"/>
153 <cell>Some other text here</cell>
154
155 <cell text="$Param2"/>
156 <cell>Some <var name="Param"> text here</cell>
157
158In the above example, four cells are written out. The first two have text hard-
159coded. The second two have variables. The third and fourth items have another
160thing that should be noted. If you have text where you want a variable in the
161middle, you have to use the latter form. Variables within parameters are the
162entire parameter's value.
163
164Please see Spreadsheet::WriteExcel for what constitutes a legal formula.
165
d0eafc11 166=head1 AUTHOR
167
c09684ff 168Rob Kinyon (rob.kinyon@gmail.com)
d0eafc11 169
170=head1 SEE ALSO
171
172ROW, VAR, FORMULA
173
174=cut