Rock笔记
~/rocknotes/articles/276.md article
// article · laravel

maatwebsite/Excel 3.1 Laravel-Excel 文档及问题笔记

...


中文文档:https://segmentfault.com/a/1190000014734174

样式设置:https://phpspreadsheet.readthedocs.io/en/latest/



问题汇总


1、问题:导出文件提示file_put_contents(): Filename cannot be empty


解决方案:修改config/excel.php文件中local_path的值为storage文件夹路径

'local_path'  => storage_path(),//sys_get_temp_dir(),


2、导入中日期变为数字

原因是导入的时候读取的实际是这个日期的常规格式,意思是从1900-01-01到这个日期一共过去了多少天。

解决方案:

$date = $row['日期'];
$d = 25569;
$t = 24 * 60 * 60;
$at = gmdate('Y-m-d H:i:s', ($date - $d) * $t);


3、导入含有多个sheet时报错Start row (2) is beyond highest row (1)

导入类里use一下WithMultipleSheets

<?php
namespace App\Helper\Excel;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class Import implements ToCollection, WithHeadingRow, WithMultipleSheets
{
	public function collection(Collection $rows)
    {
        
    }

    public function sheets(): array
    {
        return [
            0 => new static,
        ];
    }
}



回复// 0 replies

最新回复 ↓
// 暂无回复

回复功能沿用原详情页:前往原页面参与讨论 →