安装
composer require phpoffice/phpspreadsheet
简单使用
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
for($i=1;$i<=3;$i++)
{
if($i > 1)
{
$sheet = $spreadsheet->createSheet();
}
$spreadsheet->setActiveSheetIndex($i-1);
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('sheet_sheet'.$i);
$sheet->setCellValue('A1', 'Hello World !'.$i);
}
$writer = new Xlsx($spreadsheet);
$writer->save('./public/hello world.xlsx');