【问题标题】:Laravel Excel export removed last 0 from float numberLaravel Excel 导出从浮点数中删除了最后一个 0
【发布时间】:2022-10-04 17:02:56
【问题描述】:

我的数据库中有以下值。当我导出相同的内容时,它会删除最后一个 0。所以 1.10 显示为 1.1。

我尝试使用 FORMAT_NUMBER_00 进行格式化,但它最后添加了 0,甚至不需要。

It should display 1.10 instead of 1.1

【问题讨论】:

  • 使用number_format("1.10",1)php.net/manual/en/function.number-format.php
  • 不工作,我想在导出的 excel 中显示 1.10,包括 0。
  • 哦,那就用number_format("1.10",2);这个
  • @KamleshPaul 它将“1.1”值转换为“1.10”,它不应该。导出到 excel 后,如果我们使用 PHP 函数,它会删除最后一个 0。在代码中它运行良好,导出时出现问题。
  • 您使用哪个库也发布了该帖子,并且您还导出了代码

标签: laravel export maatwebsite-excel


【解决方案1】:
You means your number is $num = 012345678;
and you are trying to export CSV file its exports 12345678  right..?
so now you can use this method
$num = 0123456789;
foreach($listings as $listing){
   'number'  =>  '="'.str_replace('"', '"', $num).'"',
} 

【讨论】:

    【解决方案2】:

    我有一个解决方案并在这里发布以帮助其他人。

    use MaatwebsiteExcelConcernsWithCustomValueBinder;
    use PhpSpreadsheetCellStringValueBinder
    
    class QuestionnaireExport extends StringValueBinder implements FromCollection, WithCustomValueBinder
    

    它做了一个技巧并以原始格式导出excel,最后不删除0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-19
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多