mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Instalada libreria de PHP para Excel y hecho primer ejemplo de creacion de excel. Esta hecho el excel de giros de SK (encabezados + dummy data
This commit is contained in:
@ -667,6 +667,14 @@ $routes->group(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$routes->group(
|
||||||
|
'export-giros',
|
||||||
|
['namespace' => 'App\Controllers\Excel'],
|
||||||
|
function ($routes) {
|
||||||
|
$routes->get('generar/(:num)', 'PrintGiros::generateExcel/$1', ['as' => 'girosToExcel']);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$routes->group(
|
$routes->group(
|
||||||
'buscadorpresupuestos',
|
'buscadorpresupuestos',
|
||||||
['namespace' => 'App\Controllers\Presupuestos'],
|
['namespace' => 'App\Controllers\Presupuestos'],
|
||||||
|
|||||||
82
ci4/app/Controllers/Excel/PrintGiros.php
Normal file
82
ci4/app/Controllers/Excel/PrintGiros.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Excel;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
|
|
||||||
|
class PrintGiros extends BaseController
|
||||||
|
{
|
||||||
|
public function generateExcel($factura_id = null)
|
||||||
|
{
|
||||||
|
// AQUI CREAR LAS CONSULTAS A LA BBDD, QUIZAS HAYA QUE CREARLO O COMO POST O COMO QUERY AJAX
|
||||||
|
|
||||||
|
// Crear un nuevo Spreadsheet
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Especificar encabezados
|
||||||
|
$headers = [
|
||||||
|
'BIC (SWIFT)*',
|
||||||
|
'FECHA FIRMA MANDATO*',
|
||||||
|
'IBAN*',
|
||||||
|
'IMPORTE*',
|
||||||
|
'NOMBRE*',
|
||||||
|
'PAIS*',
|
||||||
|
'REFERENCIA DEL ADEUDO (REFADEUDO)*',
|
||||||
|
'REFERENCIA*',
|
||||||
|
'REFERENCIA DEL MANDATO (REMANDATO)*',
|
||||||
|
'RESIDENTE*',
|
||||||
|
'TIPO DE ADEUDO*',
|
||||||
|
'FECHA DE COBRO*',
|
||||||
|
'DIAS*'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Establecer los encabezados en la primera fila
|
||||||
|
$column = 'A';
|
||||||
|
foreach ($headers as $header) {
|
||||||
|
$sheet->setCellValue($column . '1', $header);
|
||||||
|
$column++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generar datos dummy
|
||||||
|
$dummyData = [
|
||||||
|
['ABCDEF12', '2024-01-01', 'ES1234567890123456789012', 100.50, 'John Doe', 'Spain', 'REF001', '12345', 'MAND001', 'Yes', 'Type1', '2024-02-01', 30],
|
||||||
|
['GHIJKL34', '2024-02-01', 'ES9876543210987654321098', 200.75, 'Jane Smith', 'France', 'REF002', '67890', 'MAND002', 'No', 'Type2', '2024-03-01', 60],
|
||||||
|
// Añade más datos dummy según sea necesario
|
||||||
|
];
|
||||||
|
|
||||||
|
// Rellenar las filas con datos dummy
|
||||||
|
$rowNumber = 2; // Empezar en la segunda fila
|
||||||
|
foreach ($dummyData as $row) {
|
||||||
|
$column = 'A';
|
||||||
|
foreach ($row as $cell) {
|
||||||
|
$sheet->setCellValue($column . $rowNumber, $cell);
|
||||||
|
$column++;
|
||||||
|
}
|
||||||
|
$rowNumber++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajustar automáticamente el tamaño de las columnas
|
||||||
|
foreach (range('A', $column) as $col) {
|
||||||
|
$sheet->getColumnDimension($col)->setAutoSize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crear un escritor para guardar el archivo
|
||||||
|
$writer = new Xlsx($spreadsheet);
|
||||||
|
|
||||||
|
// Configurar la respuesta para descarga
|
||||||
|
$fileName = 'giros_reporte.xlsx';
|
||||||
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||||
|
header('Content-Disposition: attachment;filename="' . $fileName . '"');
|
||||||
|
header('Cache-Control: max-age=0');
|
||||||
|
|
||||||
|
// Escribir el archivo a la salida
|
||||||
|
$writer->save('php://output');
|
||||||
|
exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user