Commit | Line | Data |
d0eafc11 |
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 | { |
a8441e01 |
40 | UNI_YES $txt = Unicode::String::utf8(''); |
41 | UNI_NO $txt = ''; |
d0eafc11 |
42 | } |
43 | |
44 | return $txt; |
45 | } |
46 | |
47 | sub 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 | |
61 | sub deltas |
62 | { |
63 | return { |
64 | COL => +1, |
65 | }; |
66 | } |
67 | |
68 | 1; |
69 | __END__ |
70 | |
71 | =head1 NAME |
72 | |
73 | Excel::Template::Element::Cell - Excel::Template::Element::Cell |
74 | |
75 | =head1 PURPOSE |
76 | |
77 | To actually write stuff to the worksheet |
78 | |
79 | =head1 NODE NAME |
80 | |
81 | CELL |
82 | |
83 | =head1 INHERITANCE |
84 | |
85 | Excel::Template::Element |
86 | |
87 | =head1 ATTRIBUTES |
88 | |
89 | =over 4 |
90 | |
91 | =item * TEXT |
92 | |
93 | This is the text to write to the cell. This can either be text or a parameter |
94 | with a dollar-sign in front of the parameter name. |
95 | |
96 | =item * COL |
97 | |
98 | Optionally, you can specify which column you want this cell to be in. It can be |
99 | either a number (zero-based) or an offset. See Excel::Template for more info on |
100 | offset-based numbering. |
101 | |
102 | =back 4 |
103 | |
104 | There will be more parameters added, as features are added. |
105 | |
106 | =head1 CHILDREN |
107 | |
108 | Excel::Template::Element::Formula |
109 | |
110 | =head1 EFFECTS |
111 | |
112 | This will consume one column on the current row. |
113 | |
114 | =head1 DEPENDENCIES |
115 | |
116 | None |
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 | |
126 | In the above example, four cells are written out. The first two have text hard- |
127 | coded. The second two have variables. The third and fourth items have another |
128 | thing that should be noted. If you have text where you want a variable in the |
129 | middle, you have to use the latter form. Variables within parameters are the |
130 | entire parameter's value. |
131 | |
132 | Please see Spreadsheet::WriteExcel for what constitutes a legal formula. |
133 | |
134 | =head1 BACK-REFERENCES |
135 | |
136 | Currently, you can only use a hard-coded formula. The next release will add the |
137 | capability to have a formula reference other nodes in the template dynamically. |
138 | |
139 | =head1 AUTHOR |
140 | |
c09684ff |
141 | Rob Kinyon (rob.kinyon@gmail.com) |
d0eafc11 |
142 | |
143 | =head1 SEE ALSO |
144 | |
145 | ROW, VAR, FORMULA |
146 | |
147 | =cut |