in reply to Long integers in Spreadsheet::WriteExcel
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:
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.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__
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.
--
|
|---|