Skip to content

Commit

Permalink
Fix for set_start_page() for values > 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Mar 4, 2015
1 parent c0e155b commit 0b30bd9
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 14 deletions.
7 changes: 6 additions & 1 deletion lib/Excel/Writer/XLSX/Worksheet.pm
Expand Up @@ -7230,6 +7230,11 @@ sub _write_page_setup {
push @attributes, ( 'pageOrder' => "overThenDown" );
}
# Set start page.
if ( $self->{_page_start} > 1 ) {
push @attributes, ( 'firstPageNumber' => $self->{_page_start} );
}
# Set page orientation.
if ( $self->{_orientation} == 0 ) {
push @attributes, ( 'orientation' => 'landscape' );
Expand All @@ -7240,7 +7245,7 @@ sub _write_page_setup {
# Set start page.
if ( $self->{_page_start} != 0 ) {
push @attributes, ( 'useFirstPageNumber' => $self->{_page_start} );
push @attributes, ( 'useFirstPageNumber' => 1 );
}
# Set the DPI. Mainly only for testing.
Expand Down
16 changes: 3 additions & 13 deletions t/regression/set_start_page01.t
Expand Up @@ -21,17 +21,9 @@ my $dir = 't/regression/';
my $got_filename = $dir . "ewx_$filename";
my $exp_filename = $dir . 'xlsx_files/' . $filename;

my $ignore_members = [
qw(
xl/printerSettings/printerSettings1.bin
xl/worksheets/_rels/sheet1.xml.rels
)
];
my $ignore_members = [];

my $ignore_elements = {
'[Content_Types].xml' => ['<Default Extension="bin"'],
'xl/worksheets/sheet1.xml' => ['<pageMargins'],
};
my $ignore_elements = { 'xl/worksheets/sheet1.xml' => ['<pageMargins'], };


###############################################################################
Expand All @@ -46,6 +38,7 @@ my $worksheet = $workbook->add_worksheet();
$worksheet->set_start_page(1);
$worksheet->set_paper(9);

$worksheet->{_vertical_dpi} = 200;

$worksheet->write( 'A1', 'Foo' );

Expand Down Expand Up @@ -75,6 +68,3 @@ _is_deep_diff( $got, $expected, $caption );
unlink $got_filename;

__END__
70 changes: 70 additions & 0 deletions t/regression/set_start_page02.t
@@ -0,0 +1,70 @@
###############################################################################
#
# Tests the output of Excel::Writer::XLSX against Excel generated files.
#
# reverse ('(c)'), January 2011, John McNamara, jmcnamara@cpan.org
#

use lib 't/lib';
use TestFunctions qw(_compare_xlsx_files _is_deep_diff);
use strict;
use warnings;

use Test::More tests => 1;

###############################################################################
#
# Tests setup.
#
my $filename = 'set_start_page02.xlsx';
my $dir = 't/regression/';
my $got_filename = $dir . "ewx_$filename";
my $exp_filename = $dir . 'xlsx_files/' . $filename;

my $ignore_members = [];

my $ignore_elements = { 'xl/worksheets/sheet1.xml' => ['<pageMargins'], };


###############################################################################
#
# Test the creation of a simple Excel::Writer::XLSX file with printer settings.
#
use Excel::Writer::XLSX;

my $workbook = Excel::Writer::XLSX->new( $got_filename );
my $worksheet = $workbook->add_worksheet();

$worksheet->set_start_page(2);
$worksheet->set_paper(9);

$worksheet->{_vertical_dpi} = 200;

$worksheet->write( 'A1', 'Foo' );

$workbook->close();


###############################################################################
#
# Compare the generated and existing Excel files.
#

my ( $got, $expected, $caption ) = _compare_xlsx_files(

$got_filename,
$exp_filename,
$ignore_members,
$ignore_elements,
);

_is_deep_diff( $got, $expected, $caption );


###############################################################################
#
# Cleanup.
#
unlink $got_filename;

__END__
70 changes: 70 additions & 0 deletions t/regression/set_start_page03.t
@@ -0,0 +1,70 @@
###############################################################################
#
# Tests the output of Excel::Writer::XLSX against Excel generated files.
#
# reverse ('(c)'), January 2011, John McNamara, jmcnamara@cpan.org
#

use lib 't/lib';
use TestFunctions qw(_compare_xlsx_files _is_deep_diff);
use strict;
use warnings;

use Test::More tests => 1;

###############################################################################
#
# Tests setup.
#
my $filename = 'set_start_page03.xlsx';
my $dir = 't/regression/';
my $got_filename = $dir . "ewx_$filename";
my $exp_filename = $dir . 'xlsx_files/' . $filename;

my $ignore_members = [];

my $ignore_elements = { 'xl/worksheets/sheet1.xml' => ['<pageMargins'], };


###############################################################################
#
# Test the creation of a simple Excel::Writer::XLSX file with printer settings.
#
use Excel::Writer::XLSX;

my $workbook = Excel::Writer::XLSX->new( $got_filename );
my $worksheet = $workbook->add_worksheet();

$worksheet->set_start_page(101);
$worksheet->set_paper(9);

$worksheet->{_vertical_dpi} = 200;

$worksheet->write( 'A1', 'Foo' );

$workbook->close();


###############################################################################
#
# Compare the generated and existing Excel files.
#

my ( $got, $expected, $caption ) = _compare_xlsx_files(

$got_filename,
$exp_filename,
$ignore_members,
$ignore_elements,
);

_is_deep_diff( $got, $expected, $caption );


###############################################################################
#
# Cleanup.
#
unlink $got_filename;

__END__
Binary file modified t/regression/xlsx_files/set_start_page01.xlsx
Binary file not shown.
Binary file added t/regression/xlsx_files/set_start_page02.xlsx
Binary file not shown.
Binary file added t/regression/xlsx_files/set_start_page03.xlsx
Binary file not shown.

0 comments on commit 0b30bd9

Please sign in to comment.