Revision history for Perl distribution Excel::Template
-0.16 Fri Nov 05 16:15:00 2004
+0.17 Sat Nov 05 23:30:00 2004
+ - Added worksheet protection
+ - Fixed several bugs found by adding more tests
+ - SCOPE node actually works
+ - CONDITIONAL / IF now handles string values correctly
+
+0.16 Fri Nov 05 13:30:00 2004
- Fixed Makefile.PL so that it uses PM_FILTER instead of rolling its own
- This means that the Unicode handling is cleaner from a source
perspective
t/007.xml
t/008_formula.t
t/008.xml
+t/009_loop.t
+t/009.xml
+t/010_scope.t
+t/010.xml
+t/011_conditional.t
+t/011.xml
+t/012_backref.t
+t/012.xml
+t/013_range.t
+t/013.xml
t/mock.pm
t/Spreadsheet/WriteExcel.pm
t/Spreadsheet/WriteExcel/Worksheet.pm
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Excel-Template
-version: 0.15
+version: 0.17
version_from: lib/Excel/Template.pm
installdirs: site
requires:
File::Basename: 0.01
- IO::File: 0.01
IO::Scalar: 0.01
Spreadsheet::WriteExcel: 0.42
Test::Simple: 0.44
TODO list for Perl distribution Excel::Template
- Figure out if and how to add support for charts
-- Add tests for LOOP, SCOPE, CONDITIONAL, BACKREF, and RANGE
-- Add more stringent tests for what we already have
+- Add more stringent tests
+- Add colspan (COL), rowspan (ROW), width (CELL), and height (ROW)
- Anything else people suggest
use Excel::Template::Base;
use vars qw ($VERSION @ISA);
- $VERSION = '0.16';
+ $VERSION = '0.17';
@ISA = qw( Excel::Template::Base );
}
? $isOp{$op}
: '==';
- # Force numerical context on both values;
- $value *= 1;
- $val *= 1;
-
my $res;
for ($op)
{
die "Unknown operator in conditional resolve", $/;
}
- return 0 unless $res;
+ return $res && 1;
}
- elsif (my $is = uc $context->get($self, 'IS'))
+
+ my $istrue = $val && 1;
+
+ my $is = uc $context->get($self, 'IS') || 'TRUE';
+ if ($is eq 'TRUE')
{
- my $istrue = $val && 1;
- if ($is eq 'TRUE')
- {
- return 0 unless $istrue;
- }
- else
- {
- warn "Conditional 'is' value was [$is], defaulting to 'FALSE'" . $/
- if $is ne 'FALSE';
+ return 0 unless $istrue;
+ }
+ else
+ {
+ warn "Conditional 'is' value was [$is], defaulting to 'FALSE'" . $/
+ if $is ne 'FALSE';
- return 0 if $istrue;
- }
+ return 0 if $istrue;
}
return 1;
=head1 DEPENDENCIES
-None
+You must have protected the worksheet containing any cells that are affected by
+this format. Otherwise, this node will have no effect.
=head1 USAGE
=head1 SEE ALSO
-FORMAT
+WORKSHEET, FORMAT
=cut
=head1 DEPENDENCIES
-None
+You must have protected the worksheet containing any cells that are affected by
+this format. Otherwise, this node will have no effect.
=head1 USAGE
=head1 SEE ALSO
-FORMAT
+WORKSHEET, FORMAT
=cut
$context->new_worksheet( $self );
+ my $password = $context->get( $self, 'PROTECT' );
+ if (defined $password)
+ {
+ $context->active_worksheet->protect( $password );
+ }
+
return $self->SUPER::render($context);
}
This is the name of the worksheet to be added.
+=item * PROTECT
+
+If the attribute exists, it will mark the worksheet as being protected. Whatever
+value is set will be used as the password.
+
+This activates the HIDDEN and LOCKED nodes.
+
=back 4
=head1 CHILDREN
BACKREF
RANGE
ROW
+ SCOPE
SHADOW
STRIKEOUT
VAR
--- /dev/null
+<workbook>
+ <worksheet name="loops">
+ <loop name="loopy">
+ <row>
+ <cell text="$value" />
+ <cell text="text" />
+ </row>
+ </loop>
+
+ <loop name="outer">
+ <row>
+ <cell text="$iter" />
+ <loop name="inner">
+ <cell text="$value" />
+ </loop>
+ </row>
+ </loop>
+
+ </worksheet>
+
+ <loop name="worksheets">
+ <worksheet name="$value" />
+ </loop>
+</workbook>
--- /dev/null
+use strict;
+use warnings;
+$|++;
+
+use Test::More tests => 5;
+
+use lib 't';
+use mock;
+mock->reset;
+
+my $CLASS = 'Excel::Template';
+use_ok( $CLASS );
+
+my $object = $CLASS->new(
+ filename => 't/009.xml',
+);
+isa_ok( $object, $CLASS );
+
+ok(
+ $object->param(
+ loopy => [
+ { value => 1 },
+ { value => 2 },
+ { value => 3 },
+ ],
+ outer => [
+ { iter => 'a', inner => [ { value => 1 }, { value => 2 } ] },
+ { iter => 'b', inner => [ { value => 3 }, { value => 4 } ] },
+ ],
+ worksheets => [
+ { value => 1 },
+ { value => 2 },
+ { value => 3 },
+ ],
+ ),
+ 'Parameters set',
+);
+
+ok( $object->write_file( 'filename' ), 'Something returned' );
+
+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( 'loops' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '1', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'text', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '1', '0', '2', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '1', '1', 'text', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '2', '0', '3', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '2', '1', 'text', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '3', '0', 'a', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '3', '1', '1', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '3', '2', '2', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '4', '0', 'b', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '4', '1', '3', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '4', '2', '4', '1' )
+Spreadsheet::WriteExcel::add_worksheet( '1' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::add_worksheet( '2' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::add_worksheet( '3' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
--- /dev/null
+<workbook>
+ <worksheet name="scope">
+ <scope text="1">
+ <cell />
+ <cell />
+ </scope>
+ </worksheet>
+</workbook>
--- /dev/null
+use strict;
+use warnings;
+$|++;
+
+use Test::More tests => 4;
+
+use lib 't';
+use mock;
+mock->reset;
+
+my $CLASS = 'Excel::Template';
+use_ok( $CLASS );
+
+my $object = $CLASS->new(
+ filename => 't/010.xml',
+);
+isa_ok( $object, $CLASS );
+
+ok( $object->write_file( 'filename' ), 'Something returned' );
+
+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( 'scope' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '1', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', '1', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
--- /dev/null
+<workbook>
+ <worksheet name="conditional">
+ <loop name="loopy">
+ <row>
+ <if name="int">
+ <cell text="bool" />
+ </if>
+ <if name="int" is="FALSE">
+ <cell text="not bool" />
+ </if>
+ <if name="int" op="==" value="0">
+ <cell text="int" />
+ </if>
+ <if name="char" op="eq" value="y">
+ <cell text="char" />
+ </if>
+ </row>
+ </loop>
+ </worksheet>
+</workbook>
--- /dev/null
+use strict;
+use warnings;
+$|++;
+
+use Test::More tests => 5;
+
+use lib 't';
+use mock;
+mock->reset;
+
+my $CLASS = 'Excel::Template';
+use_ok( $CLASS );
+
+my $object = $CLASS->new(
+ filename => 't/011.xml',
+);
+isa_ok( $object, $CLASS );
+
+ok(
+ $object->param(
+ loopy => [
+ { int => 0, char => 'n' },
+ { int => 0, char => 'y' },
+ { int => 1, char => 'n' },
+ { int => 1, char => 'y' },
+ ],
+ ),
+ 'Parameters set',
+);
+
+ok( $object->write_file( 'filename' ), 'Something returned' );
+
+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( 'conditional' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'not bool', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'int', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '1', '0', 'not bool', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '1', '1', 'int', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '1', '2', 'char', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '2', '0', 'bool', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '3', '0', 'bool', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '3', '1', 'char', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
--- /dev/null
+<workbook>
+ <worksheet name="backref">
+ <cell ref="foo" text="not me" />
+ <cell ref="foo" text="me" />
+ <cell>=<backref ref="foo"/></cell>
+ </worksheet>
+</workbook>
--- /dev/null
+use strict;
+use warnings;
+$|++;
+
+use Test::More tests => 4;
+
+use lib 't';
+use mock;
+mock->reset;
+
+my $CLASS = 'Excel::Template';
+use_ok( $CLASS );
+
+my $object = $CLASS->new(
+ filename => 't/012.xml',
+);
+isa_ok( $object, $CLASS );
+
+ok( $object->write_file( 'filename' ), 'Something returned' );
+
+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( 'backref' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'not me', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'me', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '2', '=B1', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
--- /dev/null
+<workbook>
+ <worksheet name="backref">
+ <cell ref="foo" text="1" />
+ <cell ref="foo" text="2" />
+ <cell ref="foo" text="3" />
+ <cell>=SUM(<range ref="foo"/>)</cell>
+ </worksheet>
+</workbook>
--- /dev/null
+use strict;
+use warnings;
+$|++;
+
+use Test::More tests => 4;
+
+use lib 't';
+use mock;
+mock->reset;
+
+my $CLASS = 'Excel::Template';
+use_ok( $CLASS );
+
+my $object = $CLASS->new(
+ filename => 't/013.xml',
+);
+isa_ok( $object, $CLASS );
+
+ok( $object->write_file( 'filename' ), 'Something returned' );
+
+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( 'backref' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '1', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', '2', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '2', '3', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '3', '=SUM(A1:C1)', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__