【问题标题】:How to disable the scientific notation when working with Perl and Excel使用 Perl 和 Excel 时如何禁用科学记数法
【发布时间】:2014-12-22 18:42:54
【问题描述】:

我正在使用 Excel::Writer::XLSX 模块在 Excel 工作表中打印数字,但大整数是以科学计数法打印的。

这可以打印为十进制数吗?例如使用

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

由于使用科学计数法打印大数字存在一些限制。

【问题讨论】:

    标签: excel perl xlsx writer


    【解决方案1】:

    正如@toolic 所提到的,你可以这样做:

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

    这将指定“无小数位”作为您的格式。

    有关格式参考,请参阅 How to control and understand settings in the Format Cells dialog box in Excel

    【讨论】:

      【解决方案2】:

      正如已经提到的,使用 set_num_format 可能是帮助您解决此问题的一种方法,但上面的答案消除了任何十进制数字 - 请参阅here 以获取可能使用的样式列表...但仅当您的数字有十五位或更少的有效数字。 Excel 将数字限制为 15 位有效数字。 https://superuser.com/questions/437764/why-is-excel-truncating-my-16-digit-numbers

      幸运的是,Excel 在字符计数方面要好一些! :) http://excel.tips.net/T003163_Character_Limits_for_Cells.html

      如果您只需要在 Excel 工作表中以小数形式显示数据,那么您可以选择将这些单元格写入字符串 - 不用担心它们会是字符串,但它们看起来非常像十进制数字;)

      use Spreadsheet::WriteExcel;
      $WORKBOOK = Spreadsheet::WriteExcel->new($PutTheFileHere);
      
      $FORMAT_STRING = $WORKBOOK->addformat(num_format => '@');
      $format = $FORMAT_STRING
      $worksheet->write($row_num, $col_num, $field_data, $format);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-01
        • 1970-01-01
        • 2018-07-09
        • 2021-01-27
        • 1970-01-01
        • 1970-01-01
        • 2014-08-23
        • 2011-07-18
        相关资源
        最近更新 更多