Update autofilter documentation
[p5sagit/Excel-Template.git] / lib / Excel / Template / Container / Worksheet.pm
CommitLineData
d0eafc11 1package Excel::Template::Container::Worksheet;
2
3use strict;
4
5BEGIN {
6 use vars qw(@ISA);
7 @ISA = qw(Excel::Template::Container);
8
9 use Excel::Template::Container;
10}
11
bf9809e5 12sub exit_scope { $_[1]->active_worksheet(undef) }
8fd01531 13
bf9809e5 14sub 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
551;
56__END__
57
58=head1 NAME
59
60Excel::Template::Container::Worksheet - Excel::Template::Container::Worksheet
61
62=head1 PURPOSE
63
64To provide a new worksheet.
65
66=head1 NODE NAME
67
68WORKSHEET
69
70=head1 INHERITANCE
71
72Excel::Template::Container
73
74=head1 ATTRIBUTES
75
76=over 4
77
78=item * NAME
79
80This is the name of the worksheet to be added.
81
dba6a68e 82=item * PROTECT
83
84If the attribute exists, it will mark the worksheet as being protected. Whatever
85value is set will be used as the password.
86
87This activates the HIDDEN and LOCKED nodes.
88
d01e4722 89=item * KEEP_LEADING_ZEROS
90
91This will change the behavior of the worksheet to preserve leading zeros.
92
bf9809e5 93
94=item * HIDE_GRIDLINE
95
96his method is used to hide the gridlines on the screen and printed page.
97Gridlines are the lines that divide the cells on a worksheet. Screen and printed gridlines are
98turned on by default in an Excel worksheet. If you have defined your own cell
99borders you may wish to hide the default gridlines.
100
101$worksheet->hide_gridlines();
102
103The 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
109If 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
113This will set the worksheet's orientation to landscape.
114
115=item * PORTRAIT
116
117This will set the worksheet's orientation to portrait.
118
119While this is the default, it's useful to override the default at times. For
120example, 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
134In that example, the first and third worksheets will be landscape (inheriting
135it from the workbook node), but the second worksheet will be portrait.
136
0ba8883c 137=item * AUTOFILTER
138
543961e9 139With these attribute, you can add the autofilter to a worksheet. An autofilter is a
140way of adding drop down lists to the headers of a 2D range of worksheet data.
141This is turn allow users to filter the data based on simple criteria so that
142some data is shown and some is hidden.
0ba8883c 143
543961e9 144Example 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
154None
155
156=head1 EFFECTS
157
158None
159
160=head1 DEPENDENCIES
161
162None
163
164=head1 USAGE
165
166 <worksheet name="My Taxes">
167 ... Children here
168 </worksheet>
169
170In the above example, the children will be executed in the context of the
171"My Taxes" worksheet.
172
173=head1 AUTHOR
174
c09684ff 175Rob Kinyon (rob.kinyon@gmail.com)
d0eafc11 176
177=head1 SEE ALSO
178
179ROW, CELL, FORMULA
180
181=cut