From: Robert Bohne Date: Thu, 17 Jun 2010 21:39:17 +0000 (+0200) Subject: Add autofilter to worksheet X-Git-Tag: v0.31_1~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ba8883c231dc58830f008aa46c69b809a7bbbff;p=p5sagit%2FExcel-Template.git Add autofilter to worksheet --- diff --git a/Changes b/Changes index fb1b0d3..c8ed818 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Perl distribution Excel::Template X.XX + - Add autofilter to worksheet - Swichting to Module::Install 0.31 Mo Dec 17 13:41:00 2007 diff --git a/lib/Excel/Template.pm b/lib/Excel/Template.pm index 0bc2562..0769f89 100644 --- a/lib/Excel/Template.pm +++ b/lib/Excel/Template.pm @@ -464,6 +464,8 @@ There is a mailing list at http://groups.google.com/group/ExcelTemplate or excel =item * Swichting to Module::Install +=item * Add autofilter to worksheet + =back =head2 Robert Graff diff --git a/lib/Excel/Template/Container/Worksheet.pm b/lib/Excel/Template/Container/Worksheet.pm index 9a789d8..3b6f26c 100644 --- a/lib/Excel/Template/Container/Worksheet.pm +++ b/lib/Excel/Template/Container/Worksheet.pm @@ -38,6 +38,17 @@ sub render { $worksheet->hide_gridlines( $hide_gridlines ); } + my $autofilter = $context->get( $self, "AUTOFILTER"); + if ( defined $autofilter ) { + if ($autofilter =~ /^\D/) { + $worksheet->autofilter($autofilter); + }else{ + $autofilter =~ s/ //g; + my ($row1, $col1, $row2, $col2) = split(',',$autofilter); + $worksheet->autofilter($row1, $col1, $row2, $col2); + } + } + return $self->SUPER::render($context); } @@ -123,6 +134,17 @@ example, in the following situation: In that example, the first and third worksheets will be landscape (inheriting it from the workbook node), but the second worksheet will be portrait. +=item * AUTOFILTER + +With these attributes, the auto filter set for the Worksheet. +See L->autofilter() + +Example: + + + + + =back =head1 CHILDREN diff --git a/t/029_worksheet_autofilter.t b/t/029_worksheet_autofilter.t new file mode 100644 index 0000000..19c4a4c --- /dev/null +++ b/t/029_worksheet_autofilter.t @@ -0,0 +1,38 @@ +use strict; + +use Test::More tests => 4; + +use lib 't'; +use mock; +use Data::Dumper; +mock::reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +my $object = $CLASS->new( + filename => \*DATA, +); +isa_ok( $object, $CLASS ); + +ok( $object->write_file( 'filename' ), 'Something returned' ); + +my @calls = mock::get_calls; +# warn Dumper \@calls; +is( join( $/, @calls, '' ), <<__END_EXPECTED__, 'Calls match up' ); +Spreadsheet::WriteExcel::new( 'filename' ) +Spreadsheet::WriteExcel::add_format( '' ) +Spreadsheet::WriteExcel::add_worksheet( '' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::Worksheet::autofilter( 'A1:D11' ) +Spreadsheet::WriteExcel::add_worksheet( '' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::Worksheet::autofilter( '0', '0', '10', '3' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__ + +__DATA__ + + + + diff --git a/t/Spreadsheet/WriteExcel/Worksheet.pm b/t/Spreadsheet/WriteExcel/Worksheet.pm index 00985da..0436735 100644 --- a/t/Spreadsheet/WriteExcel/Worksheet.pm +++ b/t/Spreadsheet/WriteExcel/Worksheet.pm @@ -19,7 +19,7 @@ sub new { my @funcs = qw( write_string write_number write_blank write_url write_formula write_date_time write set_row set_column keep_leading_zeros insert_bitmap freeze_panes - set_landscape set_portrait merge_range hide_gridlines + set_landscape set_portrait merge_range hide_gridlines autofilter ); foreach my $func ( @funcs ) {