From: Rob Kinyon Date: Fri, 2 Jun 2006 19:21:00 +0000 (+0000) Subject: r13925@rob-kinyons-powerbook58: rob | 2006-06-02 14:29:05 -0400 X-Git-Tag: v0.27~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5b1d71942c039db3b6acec7ab5551663d0390d06;p=p5sagit%2FExcel-Template.git r13925@rob-kinyons-powerbook58: rob | 2006-06-02 14:29:05 -0400 Added FreezePanes and completed Image --- diff --git a/Changes b/Changes index 63f260c..251ae25 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for Perl distribution Excel::Template 0.26 Thu Jun 01 17:00:00 2005 - Fixed how widths are whitelisted to allow '.' for fractions + - Fixed how certain formats are copied + - Added + - Added 0.25 Thu May 26 11:00:00 2005 - Changed how the template file is opened to use 3-arg open() if available diff --git a/MANIFEST b/MANIFEST index 5fc2f97..5a83c33 100644 --- a/MANIFEST +++ b/MANIFEST @@ -31,6 +31,7 @@ lib/Excel/Template/Container/Worksheet.pm lib/Excel/Template/Element/Backref.pm lib/Excel/Template/Element/Cell.pm lib/Excel/Template/Element/Formula.pm +lib/Excel/Template/Element/FreezePanes.pm lib/Excel/Template/Element/Image.pm lib/Excel/Template/Element/Range.pm lib/Excel/Template/Element/Var.pm @@ -73,6 +74,7 @@ t/021_loop_error.t t/022_keep_leading_zeros.t t/023_relative_values.t t/024_image.t +t/025_freezepanes.t t/998_pod.t t/999_pod_coverage.t t/mock.pm diff --git a/Todo b/Todo index 22d972f..f076482 100644 --- a/Todo +++ b/Todo @@ -19,7 +19,6 @@ Missing S::WE features: activate/select/set_first_sheet set_selection outline_settings - freeze_panes thaw_panes merge_range set_zoom diff --git a/lib/Excel/Template/Element/FreezePanes.pm b/lib/Excel/Template/Element/FreezePanes.pm new file mode 100644 index 0000000..db4a534 --- /dev/null +++ b/lib/Excel/Template/Element/FreezePanes.pm @@ -0,0 +1,63 @@ +package Excel::Template::Element::FreezePanes; + +use strict; + +BEGIN { + use vars qw(@ISA); + @ISA = qw(Excel::Template::Element); + + use Excel::Template::Element; +} + +sub render { + my $self = shift; + my ($context) = @_; + + my ($row, $col) = map { $context->get( $self, $_ ) } qw( ROW COL ); + $context->active_worksheet->freeze_panes( $row, $col ); + + return 1; +} + +1; +__END__ + +=head1 NAME + +Excel::Template::Element::FreezePanes - Excel::Template::Element::FreezePanes + +=head1 PURPOSE + +To insert an image into the worksheet + +=head1 NODE NAME + +FREEZEPANES + +=head1 INHERITANCE + +L + +=head1 EFFECTS + +This will not conume any columns or rows. It is a zero-width assertion. + +=head1 DEPENDENCIES + +None + +=head1 USAGE + + + +This will do a Freeze Pane at the current cell. + +=head1 AUTHOR + +Rob Kinyon (rob.kinyon@gmail.com) + +=head1 SEE ALSO + +Nothing + +=cut diff --git a/lib/Excel/Template/Element/Image.pm b/lib/Excel/Template/Element/Image.pm index 2817ad4..dd9b9dd 100644 --- a/lib/Excel/Template/Element/Image.pm +++ b/lib/Excel/Template/Element/Image.pm @@ -13,10 +13,9 @@ sub render { my $self = shift; my ($context) = @_; - my $path = $context->get( $self, 'PATH' ); - my ($row, $col, $offset, $scale) = map { + my ($row, $col, $path, $offset, $scale) = map { $context->get($self, $_) - } qw( ROW COL OFFSET SCALE ); + } qw( ROW COL PATH OFFSET SCALE ); my @offsets = (0,0); if ( $offset =~ /^\s*([\d.]+)\s*,\s*([\d.]+)/ ) { @@ -28,7 +27,7 @@ sub render { @scales = ($1,$2); } - $context->active_worksheet->insert_image( + $context->active_worksheet->insert_bitmap( $row, $col, $path, @offsets, @scales, ); @@ -54,12 +53,16 @@ To insert an image into the worksheet =head1 NODE NAME -CELL +IMAGE =head1 INHERITANCE L +=head1 EFFECTS + +This will consume one column in the current row. + =head1 DEPENDENCIES None @@ -73,6 +76,8 @@ None Please see L for more information about the offset and scaling options as well as any other restrictions that might be in place. This node does B perform any sort of validation upon your parameters. You are assumed to know what you are doing. +Note that the offset and scaling values are "X,Y". You I provide both values, even if the Y value is 0. If you provide a 0 value for either scaling option, L will default that to 1. + =head1 AUTHOR Rob Kinyon (rob.kinyon@gmail.com) diff --git a/lib/Excel/Template/Factory.pm b/lib/Excel/Template/Factory.pm index 3c86dc0..ed87510 100644 --- a/lib/Excel/Template/Factory.pm +++ b/lib/Excel/Template/Factory.pm @@ -12,12 +12,13 @@ my %Manifest = ( 'WORKBOOK' => 'Excel::Template::Container::Workbook', 'WORKSHEET' => 'Excel::Template::Container::Worksheet', - 'BACKREF' => 'Excel::Template::Element::Backref', - 'CELL' => 'Excel::Template::Element::Cell', - 'FORMULA' => 'Excel::Template::Element::Formula', - 'IMAGE' => 'Excel::Template::Element::Image', - 'RANGE' => 'Excel::Template::Element::Range', - 'VAR' => 'Excel::Template::Element::Var', + 'BACKREF' => 'Excel::Template::Element::Backref', + 'CELL' => 'Excel::Template::Element::Cell', + 'FORMULA' => 'Excel::Template::Element::Formula', + 'FREEZEPANES' => 'Excel::Template::Element::FreezePanes', + 'IMAGE' => 'Excel::Template::Element::Image', + 'RANGE' => 'Excel::Template::Element::Range', + 'VAR' => 'Excel::Template::Element::Var', 'FORMAT' => 'Excel::Template::Container::Format', @@ -49,7 +50,7 @@ my %isBuildable = map { $_ => ~~1 } qw( WORKBOOK WORKSHEET FORMAT BOLD HIDDEN ITALIC LOCKED OUTLINE SHADOW STRIKEOUT IF ROW LOOP SCOPE KEEP_LEADING_ZEROS - CELL FORMULA IMAGE + CELL FORMULA FREEZEPANES IMAGE VAR BACKREF RANGE ); diff --git a/t/024_image.t b/t/024_image.t index 0d5b33e..a0a344a 100644 --- a/t/024_image.t +++ b/t/024_image.t @@ -24,11 +24,11 @@ Spreadsheet::WriteExcel::add_format( '' ) Spreadsheet::WriteExcel::add_worksheet( '' ) Spreadsheet::WriteExcel::Worksheet::new( '' ) Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'before', '1' ) -Spreadsheet::WriteExcel::Worksheet::insert_image( '0', '1', '/full/path', '0', '0', '0', '0' ) +Spreadsheet::WriteExcel::Worksheet::insert_bitmap( '0', '1', '/full/path', '0', '0', '0', '0' ) Spreadsheet::WriteExcel::Worksheet::write( '0', '2', 'after', '1' ) -Spreadsheet::WriteExcel::Worksheet::insert_image( '0', '3', '/full/path', '2', '2', '0', '0' ) -Spreadsheet::WriteExcel::Worksheet::insert_image( '0', '4', '/full/path', '0', '0', '2', '2' ) -Spreadsheet::WriteExcel::Worksheet::insert_image( '0', '5', '/full/path', '0', '1', '1.1', '0' ) +Spreadsheet::WriteExcel::Worksheet::insert_bitmap( '0', '3', '/full/path', '2', '2', '0', '0' ) +Spreadsheet::WriteExcel::Worksheet::insert_bitmap( '0', '4', '/full/path', '0', '0', '2', '2' ) +Spreadsheet::WriteExcel::Worksheet::insert_bitmap( '0', '5', '/full/path', '0', '1', '1.1', '0' ) Spreadsheet::WriteExcel::close( '' ) __END_EXPECTED__ @@ -43,4 +43,3 @@ __DATA__ - diff --git a/t/025_freezepanes.t b/t/025_freezepanes.t new file mode 100644 index 0000000..44626c1 --- /dev/null +++ b/t/025_freezepanes.t @@ -0,0 +1,39 @@ +BEGIN{ $^W = 0 } +use strict; + +use Test::More tests => 4; + +use lib 't'; +use mock; +mock::reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +my $object = $CLASS->new( + file => \*DATA, +); +isa_ok( $object, $CLASS ); + +ok( $object->write_file( 'filename' ), 'Successfuly wrote file' ); + +my @calls = mock::get_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::write( '0', '0', 'before', '1' ) +Spreadsheet::WriteExcel::Worksheet::freeze_panes( '0', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'after', '1' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__ + +__DATA__ + + + + + + + diff --git a/t/Spreadsheet/WriteExcel/Worksheet.pm b/t/Spreadsheet/WriteExcel/Worksheet.pm index 2f6428a..a3e6d16 100644 --- a/t/Spreadsheet/WriteExcel/Worksheet.pm +++ b/t/Spreadsheet/WriteExcel/Worksheet.pm @@ -97,12 +97,21 @@ sub keep_leading_zeros { } } -sub insert_image { +sub insert_bitmap { my $self = shift; { local $" = "', '"; - push @mock::calls, __PACKAGE__ . "::insert_image( '@_' )"; + push @mock::calls, __PACKAGE__ . "::insert_bitmap( '@_' )"; + } +} + +sub freeze_panes { + my $self = shift; + + { + local $" = "', '"; + push @mock::calls, __PACKAGE__ . "::freeze_panes( '@_' )"; } }