Skip to content

Commit

Permalink
format: fix identation and alignment property mismatch
Browse files Browse the repository at this point in the history
Fix issue where a horizontal alignment format was ignored if the
indentation was also set.
  • Loading branch information
jmcnamara committed Feb 3, 2024
1 parent fbdb693 commit 24563bc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/Excel/Writer/XLSX/Format.pm
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,16 @@ sub get_align_properties {



# Indent is only allowed for horizontal left, right and distributed. If it
# is defined for any other alignment or no alignment has been set then
# default to left alignment.
# Indent is only allowed for some alignment properties. If it is defined
# for any other alignment or no alignment has been set then default to
# left alignment.
if ( $self->{_indent}
&& $self->{_text_h_align} != 1
&& $self->{_text_h_align} != 3
&& $self->{_text_h_align} != 7 )
&& $self->{_text_h_align} != 7
&& $self->{_text_v_align} != 1
&& $self->{_text_v_align} != 3
&& $self->{_text_v_align} != 5 )
{
$self->{_text_h_align} = 1;
}
Expand Down Expand Up @@ -218,8 +221,8 @@ sub get_align_properties {
push @align, 'vertical', 'justify' if $self->{_text_v_align} == 4;
push @align, 'vertical', 'distributed' if $self->{_text_v_align} == 5;

push @align, 'indent', $self->{_indent} if $self->{_indent};
push @align, 'textRotation', $self->{_rotation} if $self->{_rotation};
push @align, 'indent', $self->{_indent} if $self->{_indent};

push @align, 'wrapText', 1 if $self->{_text_wrap};
push @align, 'shrinkToFit', 1 if $self->{_shrink};
Expand Down
75 changes: 75 additions & 0 deletions t/regression/format24.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
###############################################################################
#
# Tests the output of Excel::Writer::XLSX against Excel generated files.
#
# Copyright 2000-2023, John McNamara, [email protected]
#
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
#

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 = 'format24.xlsx';
my $dir = 't/regression/';
my $got_filename = $dir . "ewx_$filename";
my $exp_filename = $dir . 'xlsx_files/' . $filename;

my $ignore_members = [];
my $ignore_elements = {};


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

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

my $format1 = $workbook->add_format(
rotation => 270,
indent => 1,
align => "center",
valign => "top"
);

$worksheet->set_row(0, 75);

$worksheet->write( 0, 0, 'ABCD', $format1 );

$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 added t/regression/xlsx_files/format24.xlsx
Binary file not shown.

0 comments on commit 24563bc

Please sign in to comment.