sanind has asked for the wisdom of the Perl Monks concerning the following question:

I am getting the following error when using addformat during hash to excel conversion. Can't locate object method "addformat" via package "Spreadsheet::WriteExcel::Worksheet" at ./gen_summary.pl line 1012, <ets_qor_report>
#!/usr/bin/perl use strict ; use envParser ; use Data::Dumper ; use Tie::IxHash ; use File::Basename ; use KscAccessDD ; use Getopt::Long ; use Text::Table ; use Spreadsheet::WriteExcel ; #use Spreadsheet::WriteExcel::Format ; <.....Hash preparation code...> my $XL = Spreadsheet::WriteExcel->new('output_file.xls'); my $WS = $XL->add_worksheet('my data'); my $format = $WS->add_format(); $format->set_bold(); $format->set_color('black'); $format->set_align('center'); $format->set_size('10'); my $count = 1 ; my ($ROW, $COL) = (0, 0); for my $colname (keys %ets_qor_hash) { $WS->write($ROW, $COL,$count); ++$COL; }
Any help is appreciated

Replies are listed 'Best First'.
Re: Error when using formatting excel output using addformat
by marto (Cardinal) on Jan 30, 2015 at 10:51 UTC

    As I said in the chatterbox, perhaps you mean add_format rather than addformat. The error thrown is pretty clear. If in doubt check the module documentation.

    Update: OP changed:

    my $format = $WS->addformat();

    to

    my $format = $WS->add_format();

    Based on my reponse.

      Hi, My bad, you are correct. it's add_format.
        Hi, I still get the error after change.
Re: Error when using formatting excel output using addformat
by roboticus (Chancellor) on Jan 30, 2015 at 12:46 UTC

    sanind:

    If I recall correctly, you add formats to the workbook, not the worksheet. Try using $XL->add_format() instead.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.