2-2
套用樣板
- 好處是不用全部都用程式來寫,可以自己設定好各種花俏的格式,程式只負責把值填上
<?php
require 'vendor/autoload.php';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('test.xlsx');
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->getCell('A1')->setValue('套用樣板測試');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="套用樣板測試.xls"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
- 簡單的樣板:text.xlsx