set_row resets the line height

108 views
Skip to first unread message

Pierre

unread,
Jan 26, 2012, 10:30:08 AM1/26/12
to Spreadsheet::WriteExcel
Hi,

According to the documentation:
| If you wish to set the format without changing the height you can
pass undef as the height parameter:
| $worksheet->set_row(0, undef, $format);

But when I try, it does not behave like this...
----------------
#!/usr/local/bin/perl -w
use strict;
use Spreadsheet::WriteExcel; # 2.37
my $workbook = Spreadsheet::WriteExcel->new("test.xls");
my $sheet1 = $workbook->add_worksheet();
my $fmttitle = $workbook->add_format(size=>20, bold=>1,
color=>'blue');
$sheet1->write(0, 0, "Title", $fmttitle);
# Here the line height is correctly set to view the text
$sheet1->set_row(0, undef, $fmttitle);
# Now the line height is reset to its default value, and this is true
even if you rewrite the cell
$sheet1->write(0, 0, "Title", $fmttitle);
$workbook->close();
----------------

I can turn around this issue but do you have any comment ?

Thanks

jmcnamara

unread,
Feb 7, 2012, 6:34:20 PM2/7/12
to Spreadsheet::WriteExcel
On Jan 26, 3:30 pm, Pierre <deh...@drever.be> wrote:
> According to the documentation:
> | If you wish to set the format without changing the height you can
> pass undef as the height parameter:
> |     $worksheet->set_row(0, undef, $format);

Hi,

First off, apologies for not replying sooner. Your question was stuck
in the moderation queue and for some reason I didn't get a
notification.

Anyway, the behaviour you are seeing is correct even if it seems
strange. In your first write() you say this:

> # Here the line height is correctly set to view the text

This happens because Excel sees that the row defaults haven't been
modified but that the text is larger than the cell so it adjusts the
height. However, this is not defined behaviour and there is no
guarantee that it will always do this. Also, other applications such
as LibreOffice or OpenOffice don't do any automatic adjustment of the
height.

In addition, once you modify the row in any way, such as adding a
format, then Excel will no longer automatically scale the cell height.
This is what you are seeing in the second case:

> # Now the line height is reset to its default value

In general you shouldn't rely on the automatic scaling and instead use
an explicit row height if you need one.

Regards,

John.
--
Reply all
Reply to author
Forward
0 new messages