<?php
// Declaramos la librería
require __DIR__ . "/vendor/autoload.php";
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spread = new Spreadsheet();
$spread
    ->getProperties()
    ->setCreator("Nestor Tapia")
    ->setLastModifiedBy('BaulPHP')
    ->setTitle('Excel creado con PhpSpreadSheet')
    ->setSubject('Excel de prueba')
    ->setDescription('Excel generado como demostración')
    ->setKeywords('PHPSpreadsheet')
    ->setCategory('Categoría Excel');
 
$fileName="Descarga_excel.xlsx";
# Crear un "escritor"
$writer = new Xlsx($spread);
# Le pasamos la ruta de guardado

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="'. urlencode($fileName).'"');
$writer->save('php://output');
?>