Revision history for Perl distribution Excel::Template
+0.29 Mon Oct 08 12:00:00 2007
+ - Added merge_range as written by Stevan Little
+
0.28 Fri Jul 31 22:00:00 2005
- Added landscape and portrait orientations for worksheets
lib/Excel/Template/Element/Formula.pm
lib/Excel/Template/Element/FreezePanes.pm
lib/Excel/Template/Element/Image.pm
+lib/Excel/Template/Element/MergeRange.pm
lib/Excel/Template/Element/Range.pm
lib/Excel/Template/Element/Var.pm
t/001_load.t
t/026_vars_in_format.t
t/026_vars_in_format.xml
t/027_landscape.t
+t/028_merge_range.t
t/998_pod.t
t/999_pod_coverage.t
t/mock.pm
use Excel::Template::Base;
use vars qw ($VERSION @ISA);
- $VERSION = '0.28';
+ $VERSION = '0.29';
@ISA = qw( Excel::Template::Base );
}
--- /dev/null
+package Excel::Template::Element::MergeRange;
+
+use strict;
+
+BEGIN {
+ use vars qw(@ISA);
+ @ISA = qw(Excel::Template::Element);
+
+ use Excel::Template::Element;
+ use Excel::Template::Element::Range;
+}
+
+sub render {
+ my $self = shift;
+ my ($context) = @_;
+
+ my $ref_name = $context->resolve($self, 'REF');
+
+ my @refs = $context->get_all_references( $ref_name );
+ (@refs)
+ || die "You must specify a ref for MERGE_RANGE";
+
+ my $range = Excel::Template::Element::Range->_join_refs(@refs);
+
+ # NOTE:
+ # we need to copy the current format
+ # because Spreadsheet::WriteExcel will
+ # mark any format used in a merged cell
+ # as being specifically for a merged cell
+ # and therefore not usable elsewhere.
+
+ my $old_format = $context->active_format;
+
+ my %values;
+ while ( my ($k, $v) = each %$self ) {
+ $values{$k} = $context->resolve( $self, $k );
+ }
+
+ my $format = $context->format_object->copy(
+ $context, $old_format, %values,
+ );
+ $context->active_format($format);
+
+ $context->active_worksheet->merge_range(
+ $range,
+ $context->get($self, 'TEXT'),
+ $format,
+ );
+
+ $context->active_format($old_format);
+
+ return 1;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Excel::Template::Element::MergeRange - Excel::Template::Element::MergeRange
+
+=head1 PURPOSE
+
+To merge a range of cells in a spreadsheet
+
+=head1 NODE NAME
+
+MERGE_RANGE
+
+=head1 INHERITANCE
+
+L<ELEMENT|Excel::Template::Element>
+
+=head1 EFFECTS
+
+This will merge a range of cells.
+
+=head1 DEPENDENCIES
+
+None
+
+=head1 USAGE
+
+ <cell ref="foo"/>
+ <cell ref="foo"/>
+ <cell ref="foo"/>
+ <merge_range ref="foo">Text to insert into merged range</merge_range>
+
+=head1 AUTHOR
+
+Stevan Little (stevan.little@iinteractive.com)
+
+=head1 SEE ALSO
+
+Nothing
+
+=cut
my @refs = $context->get_all_references( $ref_name );
return '' unless @refs;
+ return $self->_join_refs(@refs);
+}
+
+sub _join_refs {
+ my ($self, @refs) = @_;
+
my ($top, $left, $bottom, $right) =
( $refs[0][0], $refs[0][1] ) x 2;
'CELL' => 'Excel::Template::Element::Cell',
'FORMULA' => 'Excel::Template::Element::Formula',
'FREEZEPANES' => 'Excel::Template::Element::FreezePanes',
+ 'MERGE_RANGE' => 'Excel::Template::Element::MergeRange',
'IMAGE' => 'Excel::Template::Element::Image',
'RANGE' => 'Excel::Template::Element::Range',
'VAR' => 'Excel::Template::Element::Var',
WORKBOOK WORKSHEET
FORMAT BOLD HIDDEN ITALIC LOCKED OUTLINE SHADOW STRIKEOUT
IF ROW LOOP SCOPE KEEP_LEADING_ZEROS
- CELL FORMULA FREEZEPANES IMAGE
+ CELL FORMULA FREEZEPANES IMAGE MERGE_RANGE
VAR BACKREF RANGE
);
eval {
require "$filename.pm";
}; if ($@) {
- die "Cannot find or compile PM file for '$class' ($filename)\n";
+ die "Cannot find or compile PM file for '$class' ($filename) because $@\n";
}
$Loaded{$class} = ~~1;
{
my @_boolean_formats = qw(
bold italic locked hidden font_outline font_shadow font_strikeout
- text_wrap text_justlast shrink
+ text_wrap text_justlast shrink is_merged
);
my @_integer_formats = qw(
bottom_color top_color left_color right_color
);
+ my @_fake_slots = qw(
+ is_merged
+ );
+
sub _params_to_key
{
my %params = @_;
my $format = _retrieve_format($self, $new_key);
return $format if $format;
+ delete $params{$_} for @_fake_slots;
+
$format = $context->{XLS}->add_format(%params);
_assign($self, $new_key, $format);
return $format;
--- /dev/null
+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', '', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', '', '1' )
+Spreadsheet::WriteExcel::add_format( '' )
+Spreadsheet::WriteExcel::Worksheet::merge_range( 'A1:B1', 'This is the Foo Range', '2' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
+
+__DATA__
+<workbook>
+ <worksheet>
+ <cell ref="foo" />
+ <cell ref="foo" />
+ <format is_merged="1">
+ <merge_range ref="foo" text="This is the Foo Range" />
+ </format>
+ </worksheet>
+</workbook>
my @funcs = qw(
write_string write_number write_blank write_url write_formula write
set_row set_column keep_leading_zeros insert_bitmap freeze_panes
- set_landscape set_portrait
+ set_landscape set_portrait merge_range
);
foreach my $func ( @funcs ) {