Skip to content

Commit 5ac5bd8

Browse files
committed
worksheet: fix set_row() and set_default_row() interaction
Fix an issue where set_row() with the default height of 15 was ignored if set_default_row() was also used.
1 parent bdf6bc4 commit 5ac5bd8

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

lib/Excel/Writer/XLSX/Worksheet.pm

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8423,13 +8423,26 @@ sub _write_row {
84238423
push @attributes, ( 's' => $xf_index ) if $xf_index;
84248424
push @attributes, ( 'customFormat' => 1 ) if $format;
84258425

8426-
if ( $height != $self->{_original_row_height} ) {
8426+
8427+
# Only add ht parameter if the height is non-default.
8428+
if (
8429+
$height != $self->{_original_row_height}
8430+
|| ( $height == $self->{_original_row_height}
8431+
&& $height != $self->{_default_row_height} )
8432+
)
8433+
{
84278434
push @attributes, ( 'ht' => $height );
84288435
}
84298436

84308437
push @attributes, ( 'hidden' => 1 ) if $hidden;
84318438

8432-
if ( $height != $self->{_original_row_height} ) {
8439+
# Only add customFormat parameter if the height is non-default.
8440+
if (
8441+
$height != $self->{_original_row_height}
8442+
|| ( $height == $self->{_original_row_height}
8443+
&& $height != $self->{_default_row_height} )
8444+
)
8445+
{
84338446
push @attributes, ( 'customHeight' => 1 );
84348447
}
84358448

t/regression/default_row06.t

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
###############################################################################
2+
#
3+
# Tests the output of Excel::Writer::XLSX against Excel generated files.
4+
#
5+
# Copyright 2000-2024, John McNamara, jmcnamara@cpan.org
6+
#
7+
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
8+
#
9+
10+
use lib 't/lib';
11+
use TestFunctions qw(_compare_xlsx_files _is_deep_diff);
12+
use strict;
13+
use warnings;
14+
15+
use Test::More tests => 1;
16+
17+
###############################################################################
18+
#
19+
# Tests setup.
20+
#
21+
my $filename = 'default_row06.xlsx';
22+
my $dir = 't/regression/';
23+
my $got_filename = $dir . "ewx_$filename";
24+
my $exp_filename = $dir . 'xlsx_files/' . $filename;
25+
26+
my $ignore_members = [];
27+
my $ignore_elements = {};
28+
29+
30+
###############################################################################
31+
#
32+
# Test the creation of a simple Excel::Writer::XLSX file.
33+
#
34+
use Excel::Writer::XLSX;
35+
36+
my $workbook = Excel::Writer::XLSX->new( $got_filename );
37+
my $worksheet = $workbook->add_worksheet();
38+
39+
$worksheet->set_default_row( 24 );
40+
$worksheet->set_row( 4, 15 );
41+
42+
$worksheet->write( 'A1', 'Foo' );
43+
$worksheet->write( 'A10', 'Bar' );
44+
45+
$workbook->close();
46+
47+
48+
###############################################################################
49+
#
50+
# Compare the generated and existing Excel files.
51+
#
52+
53+
my ( $got, $expected, $caption ) = _compare_xlsx_files(
54+
55+
$got_filename,
56+
$exp_filename,
57+
$ignore_members,
58+
$ignore_elements,
59+
);
60+
61+
_is_deep_diff( $got, $expected, $caption );
62+
63+
64+
###############################################################################
65+
#
66+
# Cleanup.
67+
#
68+
unlink $got_filename;
69+
70+
__END__
71+
72+
73+
7.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)