<?php
/**
 * Created by PhpStorm.
 * User: JairDev
 * Date: 09/12/19
 * Time: 2:54 PM
 */

require 'includes/conex_bd.php';
require 'includes/clase_sesion.php';
require 'vendor/autoload.php';

$sess = new sesion();
$anio = $sess->get('anio') || 2019;
$anio =2019;
require 'Models/configOrm.php';
use Models\Estudinate;

$d = Estudinate::where('cod_estudiante','<', 110)->get()->toArray();

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spread = new Spreadsheet();
$spread
    ->getProperties()
    ->setCreator("Nombre del autor")
    ->setLastModifiedBy('Juan Perez')
    ->setTitle('Excel creado con PhpSpreadSheet')
    ->setSubject('Excel de prueba')
    ->setDescription('Excel generado como prueba')
    ->setKeywords('PHPSpreadsheet')
    ->setCategory('Categoría de prueba');

$sheet = $spread->getActiveSheet();

$sheet->setTitle("Hoja 1");
$sheet->setCellValueByColumnAndRow(1, 1, "Valor en la posición 1, 1");
$sheet->setCellValue("B2", "Valor en celda B2");

$sheet->fromArray($d,null,'A5');

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Reporte Excel.Xlsx"');
header('Cache-Control: max-age=0');

$writer = IOFactory::createWriter($spread, 'Xlsx');
$writer->save('php://output');
exit;
exit;