You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
894 B
38 lines
894 B
<?php |
|
|
|
namespace App\Exports; |
|
|
|
use Maatwebsite\Excel\Concerns\FromArray; |
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
|
use Maatwebsite\Excel\Concerns\WithCustomStartCell; |
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
|
|
|
class ArrayExport implements FromArray, WithHeadings, WithCustomStartCell |
|
{ |
|
protected $data; |
|
protected $headings; |
|
protected $startCell; |
|
|
|
public function __construct(array $data, array $headings = null, string $startCell = 'A1') |
|
{ |
|
$this->data = $data; |
|
$this->headings = $headings; |
|
$this->startCell = $startCell; |
|
} |
|
|
|
public function array(): array |
|
{ |
|
return $this->data; |
|
} |
|
|
|
public function headings(): array |
|
{ |
|
// 定義標題列 |
|
return $this->headings ?? array_keys($this->data[0]); |
|
} |
|
|
|
public function startCell(): string |
|
{ |
|
return $this->startCell ?? 'A1'; |
|
} |
|
}
|
|
|