Search code examples
excelperlxlsxwriter

How to disable the scientific notation when working with Perl and Excel


I am printing the numbers in an Excel worksheet using the Excel::Writer::XLSX module, but big integers are being printed in scientific notation.

Can this be printed as a decimal number? For example using

$worksheet->write_number( 0, 0, 123456 );
$worksheet->write_number( 'A2', 2.3451 );

There is some limit due to which big numbers are printed in scientific notation.


Solution

  • As alluded to by @toolic, you can do something like this:

    my $format = $workbook->add_format( );
    $format->set_num_format( '#' );    
    $worksheet->write_number( 'A1', 1234567890, $format );
    

    That will specify "no decimal places" as your format.

    See How to control and understand settings in the Format Cells dialog box in Excel for formatting reference.