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

Excel table column header formatting using header_format for PERL #227

Closed perlAddict closed 5 years ago

perlAddict commented 5 years ago

Hi,

I am trying to add formatting to my header row using

my $format = $workbook->add_format(text_wrap => 1);
my @colDefs = (
    {
        header => 'Column 1',
        header_format => $format,
    }
 );

The formatting doesn't get applied. 'header_format' doesn't work but 'format' works (but I want to apply formatting to header not the column data). Is this feature enabled?

jmcnamara commented 5 years ago

Can you add a small complete working example the demonstrates the issue.

perllAddict commented 5 years ago

The following example creates the table but does not apply the header formatting.

#!/tool/pandora64/bin/perl5.8.8

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

my $workbook = Excel::Writer::XLSX->new("example.xlsx");
my $worksheet = $workbook->add_worksheet('example');

my $table = [
    ['data1','data2','data3',],
    ['data4','data5','data6',],
    ['data7','data8','data9',]
];

my $format = $workbook->add_format(text_wrap => 1);

my @colDefs = (
    {
        header => 'This is the first column',
        header_format => $format,
    },
    {
        header => 'This is the second column',
        header_format => $format,
    },
    {
        header => 'This is the third column',
        header_format => $format,
    },
);

$worksheet->add_table(
    2,0, scalar(@$table)+2, scalar(@colDefs)-1,
    {
        data => $table,
        columns     => \@colDefs,        
        style => 'None',
    }
);

$workbook->close();
jmcnamara commented 5 years ago

It appears to apply the formatting header. Here is the output from your program:

screenshot

Am I missing something?

perllAddict commented 5 years ago

I am not sure why but running that same program doesn't apply the header formatting for me. Do you have any idea what might be the cause of this issue?

jmcnamara commented 5 years ago

What version of Excel::Writer::XLSX are you using? And what version of Excel?

jmcnamara commented 5 years ago

Any followup on this?

jmcnamara commented 5 years ago

Closing as unreproducible.