in reply to Re: Spreadsheet::WriteExcel, numbers v strings?
in thread Spreadsheet::WriteExcel, numbers v strings?

Hello John, I am facing the same issue and don't think after reading this thread i got the answer to the issue. $worksheet->write ('A1', 12345); $worksheet->write ('A2', 1,2345.67); The second statement writes the value as a string in excel rather a formatted number. ie in Excel the value in A2 is stored as text and hence no mathematical operation can be performed on this value. Any suggestions? Since I am writing the values from a file - i don't know before hand if the value is numeric or string & hence i would have expected the write statement to take care of it appropriately. Appreciate your help, Thanks, Sanju
  • Comment on Re^2: Spreadsheet::WriteExcel, numbers v strings?

Replies are listed 'Best First'.
Re^3: Spreadsheet::WriteExcel, numbers v strings?
by jmcnamara (Monsignor) on Mar 20, 2008 at 04:30 UTC

    The problem is caused by the comma in your number strings. Remove that and you should get the result that you expect.

    --
    John.

      I have a similar problem: if I do something like: $worksheet->write_string('A2', '0123'); I get the number in my Excel 2002 spreadsheet displayed as "0123" as desired - but with the annoying green triangle in Excel suggesting I have "Number displayed as string". Is there a way from the Perl WriteExcel side of making the green triangle disappear?

        If you want to avoid the "Number stored as text" warnings in Excel then you will have to write the data as numbers and format it to have a padded leading zero. Item 3 of the example below demonstrates this.
        #!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new('test.xls'); my $worksheet = $workbook->addworksheet(); # A padded number format my $format = $workbook->add_format(num_format => '0000'); # 1. Implicitly write a number, the leading zero is removed: 123 $worksheet->write('B2', '0123'); # 2. Write explicitly as a string: 0123 $worksheet->write_string('B3', '0123'); # 3. Write a zero padded number using a format: 0123 $worksheet->write('B4', '0123', $format); __END__

        --
        John.

      Hey Mr McNamara, I have a question if you wouldn't mind. When working with multiple excel spreadsheets that are exactly the same with just the difference being in the data, is it possible to just create another keeping all the headers, columns, rows, colors and any other field and just replacing the data. I have to take in about a weeks worth of reports and add the numbers. Instead of having to create headings and all the bells and whistles I was hoping I could just incorporate whatever is in the existing Spreadsheets. Thanks.
      Hey John, is there a way to write numbers into the xlsx sheet, but comma separated.