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