Numbers in that range are at the limit of what can be stored in the IEEE 754 doubles used by Excel. You can verify this yourself by copying and pasting that ID number into Excel. It will appear as 1E+15 in the cell and as 1000000000002650 in the formula bar (note 50 not 51 at the end).

So, you need to use the write_string() method to write the ID as a string to the Excel file. See the output from the following program:

use warnings; use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new( 'perl.xls' ); my $worksheet = $workbook->add_worksheet(); my $id_format = $workbook->add_format( num_format => '@' ); my $id = '1000000000002651'; $worksheet->set_column( 'A:B', 30 ); $worksheet->write_string( 'A1', $id ); $worksheet->write_string( 'B1', $id, $id_format ); __END__
I've added a number format to the second example. It isn't strictly needed but it will prevent the string reverting to a number if it is edited.

If your tried write_string() and it didn't work then perhaps the ID had already been converted to a number, and as a result lost precision, in another part of your program.

--
John.

In reply to Re: Long integers in Spreadsheet::WriteExcel by jmcnamara
in thread Long integers in Spreadsheet::WriteExcel by mrguy123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.