Laravel 5.4 Maatwebsite Excel将列格式设置为数字 [英] Laravel 5.4 Maatwebsite Excel set column format to number
本文介绍了Laravel 5.4 Maatwebsite Excel将列格式设置为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将列/单元格类型设置为数字.我收到数字存储为文本".我尝试了几种组合,但没有任何效果.
I'm trying to set the column/cell type to number. I'm getting "Number stored as text". I tried several combinations but none have any effect.
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);
}
知道我在做什么错吗?
推荐答案
检查您在$type
变量中传递了什么.如果您传递CSV
,则不会格式化单元格,但是如果您传递XLS
,它将对其进行格式化.
Check what are you passing in the $type
variable. if you are passing CSV
it wouldn't formate the cell but if you are passing XLS
, it will format it.
这篇关于Laravel 5.4 Maatwebsite Excel将列格式设置为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文