【问题标题】:Laravel 5.4 Maatwebsite Excel set column format to numberLaravel 5.4 Maatwebsite Excel 将列格式设置为数字
【发布时间】:2017-10-09 12:11:18
【问题描述】:

我正在尝试将列/单元格类型设置为数字。我收到“数字存储为文本”。我尝试了几种组合,但没有任何效果。

return Excel::create('Orders', function ($excel) use ($data) {
    $excel->setTitle('Open orders');
    $excel->setKeywords('orders, excel, export');

$excel->sheet('Open orders', function ($sheet) use ($data) {
 // $sheet->getStyle('C2:C10')->getNumberFormat()->setFormatCode('0.00'); // no effect
//    $sheet->setColumnFormat(array('C2:C10' => '0')); // no effect
$sheet->setColumnFormat(array('C2:C10' => '#0')); // no effect
// $sheet->getStyle('C2:C10')->getNumberFormat()->setFormatCode('$#,###'); // no effect

            $sheet->fromArray($data);
            $sheet->freezeFirstRow();
            $sheet->row(1, function ($row) {
            $row->setBackground('#aaffaa');
            $row->setBorder('solid', 'none', 'none', 'solid');
            });
        });
    })->download($type);
}

知道我做错了什么吗?

【问题讨论】:

  • 我也有同样的问题你有答案吗?
  • 对此有什么答案吗?我希望我的单元格将文本格式化为列
  • 嗨,我通过将一个数组移动到另一个数组来解决这个问题,并在此过程中将值转换为浮点数:$arrayFinal[$i] = (float)$arrayOrg[$i]。没有其他方法对我有用。

标签: laravel-5.4 phpexcel maatwebsite-excel


【解决方案1】:

检查你在$type 变量中传递了什么。如果您传递CSV,它不会格式化单元格,但如果您传递XLS,它将格式化它。

【讨论】:

  • $type 是什么意思?如果我通过日期它的自动标签
猜你喜欢
  • 1970-01-01
  • 2022-07-26
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
  • 1970-01-01
  • 2017-11-12
  • 2018-06-23
  • 2016-06-07
相关资源
最近更新 更多