getActiveSheet(); $fileName = "sample.xlsx"; //ファイル名を設定 $sheet->setTitle("シートタイトル"); //シートタイトル名を設定 /* 画像の追加 */ $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); $drawing->setPath('logo1.png'); //元の画像パス $drawing->setCoordinates('B3'); //追加するセル位置 //$drawing->setResizeProportional(false);//リサイズ時に縦横比率を固定する (false = 固定しない) //$drawing->setWidth(100); //画像の幅(px) //$drawing->setHeight(100); //画像の高さ(px) //$drawing->setName('名前'); //名前 //$drawing->setDescription('概要'); //概要 //$drawing->setOffsetX(110); //位置をずらす //$drawing->setRotation(30); //回転(30度右に傾く) //$drawing->getShadow()->setVisible(true);//ドロップシャドウ //$drawing->getShadow()->setDirection(45);//ドロップシャドウの方向 $drawing->setWorksheet($spreadsheet->getActiveSheet()); /* Excelファイルのダウンロード */ header("Content-Description: File Transfer"); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //EXCELファイル( .xlsx OFFICE 2007以降) header('Content-Disposition: attachment; filename="'.$fileName.'"'); //ダウンロード時のファイル名をセット header('Cache-Control: no-store, max-age=0'); //新しいリソースのキャッシュを防止、キャッシュのクリア ob_end_clean(); //バッファ消去 $writer = new Xlsx($spreadsheet); $writer->save('php://output'); ?>