-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportar_excel.php
More file actions
40 lines (33 loc) · 1.38 KB
/
exportar_excel.php
File metadata and controls
40 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// exportar_excel.php - Archivo para exportar fichas a Excel
require_once 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fichas'])) {
$fichas = json_decode($_POST['fichas'], true);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// Agregar encabezados
$sheet->setCellValue('A1', 'Número de Ficha');
$sheet->setCellValue('B1', 'Número de Archivo');
$sheet->setCellValue('C1', 'Estantería');
$sheet->setCellValue('D1', 'Fecha de Creación');
$sheet->setCellValue('E1', 'Usuario');
// Agregar datos de fichas
$row = 2;
foreach ($fichas as $ficha) {
$sheet->setCellValue('A' . $row, $ficha['numero']);
$sheet->setCellValue('B' . $row, $ficha['numero_archivo']);
$sheet->setCellValue('C' . $row, $ficha['estanteria']);
$sheet->setCellValue('D' . $row, $ficha['fecha_creacion']);
$sheet->setCellValue('E' . $row, $ficha['username']);
$row++;
}
// Descargar el archivo Excel
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="fichas.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
}
?>