Commit | Line | Data |
d0eafc11 |
1 | package Excel::Template::Container::Worksheet; |
2 | |
3 | use strict; |
4 | |
5 | BEGIN { |
6 | use vars qw(@ISA); |
7 | @ISA = qw(Excel::Template::Container); |
8 | |
9 | use Excel::Template::Container; |
10 | } |
11 | |
bf9809e5 |
12 | sub exit_scope { $_[1]->active_worksheet(undef) } |
8fd01531 |
13 | |
bf9809e5 |
14 | sub render { |
d0eafc11 |
15 | my $self = shift; |
16 | my ($context) = @_; |
17 | |
bf9809e5 |
18 | my $worksheet = $context->new_worksheet($self); |
d0eafc11 |
19 | |
dba6a68e |
20 | my $password = $context->get( $self, 'PROTECT' ); |
bf9809e5 |
21 | if ( defined $password ) { |
22 | $worksheet->protect($password); |
dba6a68e |
23 | } |
24 | |
bf9809e5 |
25 | $worksheet->keep_leading_zeros(1) |
26 | if $context->mark('keep_leading_zeros'); |
d01e4722 |
27 | |
82112547 |
28 | if ( $context->get( $self, 'LANDSCAPE' ) && !$self->{PORTRAIT} ) { |
29 | $worksheet->set_landscape; |
bf9809e5 |
30 | } elsif ( $context->get( $self, 'PORTRAIT' ) ) { |
82112547 |
31 | $worksheet->set_portrait; |
32 | } |
33 | |
bf9809e5 |
34 | |
35 | my $hide_gridlines = $context->get( $self, 'HIDE_GRIDLINES'); |
36 | |
37 | if ( defined $hide_gridlines ) { |
38 | $worksheet->hide_gridlines( $hide_gridlines ); |
39 | } |
40 | |
0ba8883c |
41 | my $autofilter = $context->get( $self, "AUTOFILTER"); |
42 | if ( defined $autofilter ) { |
43 | if ($autofilter =~ /^\D/) { |
44 | $worksheet->autofilter($autofilter); |
45 | }else{ |
46 | $autofilter =~ s/ //g; |
47 | my ($row1, $col1, $row2, $col2) = split(',',$autofilter); |
48 | $worksheet->autofilter($row1, $col1, $row2, $col2); |
49 | } |
50 | } |
51 | |
d0eafc11 |
52 | return $self->SUPER::render($context); |
53 | } |
54 | |
55 | 1; |
56 | __END__ |
57 | |
58 | =head1 NAME |
59 | |
60 | Excel::Template::Container::Worksheet - Excel::Template::Container::Worksheet |
61 | |
62 | =head1 PURPOSE |
63 | |
64 | To provide a new worksheet. |
65 | |
66 | =head1 NODE NAME |
67 | |
68 | WORKSHEET |
69 | |
70 | =head1 INHERITANCE |
71 | |
72 | Excel::Template::Container |
73 | |
74 | =head1 ATTRIBUTES |
75 | |
76 | =over 4 |
77 | |
78 | =item * NAME |
79 | |
80 | This is the name of the worksheet to be added. |
81 | |
dba6a68e |
82 | =item * PROTECT |
83 | |
84 | If the attribute exists, it will mark the worksheet as being protected. Whatever |
85 | value is set will be used as the password. |
86 | |
87 | This activates the HIDDEN and LOCKED nodes. |
88 | |
d01e4722 |
89 | =item * KEEP_LEADING_ZEROS |
90 | |
91 | This will change the behavior of the worksheet to preserve leading zeros. |
92 | |
bf9809e5 |
93 | |
a3414f52 |
94 | =item * HIDE_GRIDLINES |
bf9809e5 |
95 | |
96 | his method is used to hide the gridlines on the screen and printed page. |
97 | Gridlines are the lines that divide the cells on a worksheet. Screen and printed gridlines are |
98 | turned on by default in an Excel worksheet. If you have defined your own cell |
99 | borders you may wish to hide the default gridlines. |
100 | |
101 | $worksheet->hide_gridlines(); |
102 | |
103 | The following values of $option are valid: |
104 | |
105 | 0 : Don't hide gridlines |
106 | 1 : Hide printed gridlines only |
107 | 2 : Hide screen and printed gridlines |
108 | |
109 | If you don't supply an argument or use undef the default option is 1, i.e. only the printed gridlines are hidden. |
110 | |
82112547 |
111 | =item * LANDSCAPE |
112 | |
113 | This will set the worksheet's orientation to landscape. |
114 | |
115 | =item * PORTRAIT |
116 | |
117 | This will set the worksheet's orientation to portrait. |
118 | |
119 | While this is the default, it's useful to override the default at times. For |
120 | example, in the following situation: |
121 | |
122 | <workbook landscape="1"> |
123 | <worksheet> |
124 | ... |
125 | </worksheet |
126 | <worksheet portrait="1"> |
127 | ... |
128 | </worksheet |
129 | <worksheet> |
130 | ... |
131 | </worksheet |
132 | </workbook> |
133 | |
134 | In that example, the first and third worksheets will be landscape (inheriting |
135 | it from the workbook node), but the second worksheet will be portrait. |
136 | |
0ba8883c |
137 | =item * AUTOFILTER |
138 | |
543961e9 |
139 | With these attribute, you can add the autofilter to a worksheet. An autofilter is a |
140 | way of adding drop down lists to the headers of a 2D range of worksheet data. |
141 | This is turn allow users to filter the data based on simple criteria so that |
142 | some data is shown and some is hidden. |
0ba8883c |
143 | |
543961e9 |
144 | Example to add an autofilter to a worksheet: |
0ba8883c |
145 | <workbook> |
146 | <worksheet autofilter='A1:D11' /> |
147 | <worksheet autofilter='0, 0, 10, 3' /> |
148 | </workbook> |
149 | |
6dd4c89d |
150 | =back |
d0eafc11 |
151 | |
152 | =head1 CHILDREN |
153 | |
154 | None |
155 | |
156 | =head1 EFFECTS |
157 | |
158 | None |
159 | |
160 | =head1 DEPENDENCIES |
161 | |
162 | None |
163 | |
164 | =head1 USAGE |
165 | |
166 | <worksheet name="My Taxes"> |
167 | ... Children here |
168 | </worksheet> |
169 | |
170 | In the above example, the children will be executed in the context of the |
171 | "My Taxes" worksheet. |
172 | |
173 | =head1 AUTHOR |
174 | |
c09684ff |
175 | Rob Kinyon (rob.kinyon@gmail.com) |
d0eafc11 |
176 | |
177 | =head1 SEE ALSO |
178 | |
179 | ROW, CELL, FORMULA |
180 | |
181 | =cut |