开发者

perl csv not full number not displaying in cell

Am generating the csv file, there is a problem in printing number on CELL,

Actual number is 1298271527197400000

but in my cell it display li开发者_如何学运维ke 1.29827E+18

i dont want this shortcut , i want to show full number,


Assuming you're using the popular and excellent Spreadsheet::WriteExcel module from CPAN (you didn't actually specify), you'll need to specify a format for the cell, similar to the following:

  my $fmt = $workbook->add_format( num_format => '0' );
  $worksheet->write_string( 'A2', 1298271527197400000, $fmt );

More information here:

http://search.cpan.org/dist/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel.pm#FORMAT_METHODS

and you can get a sample by running the module's examples/formats.pl script, which outputs a demo workbook called formats.xls, that shows you the various formats on your system.

Note: It may still appear in the top bar in scientific notation, but if you adjust the column width to fit the number, it displays in the actual cell in standard decimal format.


Since I clearly need more coffee: You can use the above module to directly generate a well-formatted spreadsheet for Excel, in addition to providing a CSV output option for other tools.


If you're using Excel, right-click the cell, click the "Cell formatting" entry (or whatever looks closest to that), find the number formats, and look around for an entry that doesn't use scientific or engineering formats.


If you are opening your CSV file in Excel the only safe way to load a large number is to treat it as text as it is imported. To do this change the file extension to .txt, and then select the file in Excel's open dialog. This will start the text import wizard.

  • On step 1 pick Delimited.
  • On step 2 pick only Comma as the Delimiter and " as Text Qualifier.
  • On step 3 pick the column containing the large number and select Text as the data format.

All this is based on Excel 2003, other versions will almost certainly be different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜