jmcnamara / excel-writer-xlsx

Perl module to create Excel XLSX files.
https://metacpan.org/pod/distribution/Excel-Writer-XLSX/lib/Excel/Writer/XLSX.pm
Other
100 stars 51 forks source link

problem with set_column() width #205

Closed brpays closed 6 years ago

brpays commented 6 years ago

Hello,

I have an issue when setting the column width of an XLSX file if I modify the size of default font size.

#!/usr/bin/perl
use v5.16; 

use strict;
use warnings;
use utf8;
use Excel::Writer::XLSX;

my $workbook    = Excel::Writer::XLSX->new( 'test_workbook.xlsx', { default_format_properties => { font => 'Calibri', size => 12 } } );
my $worksheet   = $workbook->add_worksheet( 'sheet1' );

$worksheet->set_column( 0, 0, 20 );
$worksheet->set_column( 1, 1, 30 );
$worksheet->set_column( 2, 2, 40 );
$worksheet->set_row( 0, 20 );
$worksheet->set_row( 1, 30 );
$worksheet->set_row( 2, 40 );

$workbook->close();

test_workbook.xlsx

column1 column2

The expected column size was 20 and 30.

jmcnamara commented 6 years ago

I have an issue ... if I modify the size of default font size.

Column widths and row heights in Excel depend on the default font for the workbook/worksheet.

So if you change the default font size (which isn't exposed publicly) then the calculations for row and column will change. This also in turn affects the calculations for worksheet objects sizing such as images, charts and comments.

You can potentially work around this by setting the following worksheet parameters for the font you define:

    $self->{_default_row_height}  = 15;
    $self->{_default_row_pixels}  = 20;
    $self->{_default_col_pixels}  = 64;

However, since all of this is internal to Excel::Writer::XLSX and not intentionally publicly exposed, I'm going to close this issue.