excel Operation Notes

csv operation

$fp = fopen($filePath, 'a+');
fputcsv($fp, ['a' => 'a', 'b' => 'b']);

  

Problem: Excel has detected "xxx.xsl" is SYLK files, but can not be loaded Solution

Solution: If any of the lowercase letter ID will not be replaced in this problem, it is estimated that fixed identification "ID" or "ID_XXXX"

 

maatwebsite / excel extension 
https://github.com/maatwebsite/Laravel-Excel
https://segmentfault.com/a/1190000014734174?utm_source=index-hottest

 Introduction of

$ App-> register (\ Size Site \ Excel \ Excel Service Provider :: class);

 The definition of class

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class logExcelExport implements FromCollection, WithHeadings
{
    public $data;

    public function __construct($data)
    {
        $this->data = collect($data);
    }

    public function collection()
    {
        return $this->data;
    }

    public function headings(): array
    {
        return [
            'ID',
            '标识',
            '备注',
            '创建时间',
            '更新时间',
        ];
    }
}

 transfer

Excel::store(new logExcelExport($data), $filePath);

  

 

Guess you like

Origin www.cnblogs.com/cxscode/p/12101583.html