Browse Source

EXCEL

Ya funciona al 100% crear un excel
main^2
Rubi 5 days ago
parent
commit
0563a79214
  1. 22
      app/Exports/tiposLicenciasExport.php
  2. 3
      composer.json
  3. 109
      composer.lock
  4. 333
      config/excel.php

22
app/Exports/tiposLicenciasExport.php

@ -3,6 +3,7 @@
namespace App\Exports;
use App\Models\tiposLicencias;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
@ -11,13 +12,20 @@ class TiposLicenciasExport implements FromCollection, WithHeadings
/**
* Método que devuelve la colección de datos a exportar.
*
* @return \Illuminate\Support\Collection
* @return Collection
*/
public function collection()
{
return tiposLicencias::where('eliminado', 0) // Solo marcas activas
->select('id', 'tipoLicencia') // Selecciona los campos que deseas exportar
->get();
return tiposLicencias::where('eliminado', 1)
->get()
->map(function($licencia) {
return [
$licencia->id,
$licencia->tipoLicencia,
$licencia->eliminado ? 'Activo' : 'Inactivo',
$licencia->created_at ? $licencia->created_at->format('d/m/Y') : ''
];
});
}
/**
@ -28,8 +36,10 @@ class TiposLicenciasExport implements FromCollection, WithHeadings
public function headings(): array
{
return [
'ID', // Encabezado para la columna ID
'Tipo de licencia', // Encabezado para la columna Tipo de licencia
'ID',
'Tipo de Licencia',
'Estado',
'Fecha de Creación'
];
}
}

3
composer.json

@ -12,7 +12,8 @@
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.6",
"maatwebsite/excel": "^3.1"
"maatwebsite/excel": "3.1.48",
"psr/simple-cache": "2.0"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

109
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fe2612b7b0bc8d9bd48499fcb0b1cc71",
"content-hash": "6b2a345146d28f6cd5eacc49b8104410",
"packages": [
{
"name": "barryvdh/laravel-dompdf",
@ -1098,16 +1098,16 @@
},
{
"name": "guzzlehttp/guzzle",
"version": "7.9.2",
"version": "7.9.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "d281ed313b989f213357e3be1a179f02196ac99b"
"reference": "7b2f29fe81dc4da0ca0ea7d42107a0845946ea77"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b",
"reference": "d281ed313b989f213357e3be1a179f02196ac99b",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/7b2f29fe81dc4da0ca0ea7d42107a0845946ea77",
"reference": "7b2f29fe81dc4da0ca0ea7d42107a0845946ea77",
"shasum": ""
},
"require": {
@ -1204,7 +1204,7 @@
],
"support": {
"issues": "https://github.com/guzzle/guzzle/issues",
"source": "https://github.com/guzzle/guzzle/tree/7.9.2"
"source": "https://github.com/guzzle/guzzle/tree/7.9.3"
},
"funding": [
{
@ -1220,20 +1220,20 @@
"type": "tidelift"
}
],
"time": "2024-07-24T11:22:20+00:00"
"time": "2025-03-27T13:37:11+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "2.0.4",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455"
"reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/f9c436286ab2892c7db7be8c8da4ef61ccf7b455",
"reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455",
"url": "https://api.github.com/repos/guzzle/promises/zipball/7c69f28996b0a6920945dd20b3857e499d9ca96c",
"reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c",
"shasum": ""
},
"require": {
@ -1287,7 +1287,7 @@
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/2.0.4"
"source": "https://github.com/guzzle/promises/tree/2.2.0"
},
"funding": [
{
@ -1303,20 +1303,20 @@
"type": "tidelift"
}
],
"time": "2024-10-17T10:06:22+00:00"
"time": "2025-03-27T13:27:01+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "2.7.0",
"version": "2.7.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201"
"reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/a70f5c95fb43bc83f07c9c948baa0dc1829bf201",
"reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/c2270caaabe631b3b44c85f99e5a04bbb8060d16",
"reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16",
"shasum": ""
},
"require": {
@ -1403,7 +1403,7 @@
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.7.0"
"source": "https://github.com/guzzle/psr7/tree/2.7.1"
},
"funding": [
{
@ -1419,7 +1419,7 @@
"type": "tidelift"
}
],
"time": "2024-07-18T11:15:46+00:00"
"time": "2025-03-27T12:30:47+00:00"
},
{
"name": "guzzlehttp/uri-template",
@ -2407,29 +2407,28 @@
},
{
"name": "maatwebsite/excel",
"version": "3.1.64",
"version": "3.1.48",
"source": {
"type": "git",
"url": "https://github.com/SpartnerNL/Laravel-Excel.git",
"reference": "e25d44a2d91da9179cd2d7fec952313548597a79"
"reference": "6d0fe2a1d195960c7af7bf0de760582da02a34b9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/e25d44a2d91da9179cd2d7fec952313548597a79",
"reference": "e25d44a2d91da9179cd2d7fec952313548597a79",
"url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/6d0fe2a1d195960c7af7bf0de760582da02a34b9",
"reference": "6d0fe2a1d195960c7af7bf0de760582da02a34b9",
"shasum": ""
},
"require": {
"composer/semver": "^3.3",
"ext-json": "*",
"illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0||^12.0",
"php": "^7.0||^8.0",
"phpoffice/phpspreadsheet": "^1.29.9",
"psr/simple-cache": "^1.0||^2.0||^3.0"
"illuminate/support": "5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0",
"php": "^7.0|^8.0",
"phpoffice/phpspreadsheet": "^1.18",
"psr/simple-cache": "^1.0|^2.0|^3.0"
},
"require-dev": {
"laravel/scout": "^7.0||^8.0||^9.0||^10.0",
"orchestra/testbench": "^6.0||^7.0||^8.0||^9.0||^10.0",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"predis/predis": "^1.1"
},
"type": "library",
@ -2472,7 +2471,7 @@
],
"support": {
"issues": "https://github.com/SpartnerNL/Laravel-Excel/issues",
"source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.64"
"source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.48"
},
"funding": [
{
@ -2484,7 +2483,7 @@
"type": "github"
}
],
"time": "2025-02-24T11:12:50+00:00"
"time": "2023-02-22T21:01:38+00:00"
},
{
"name": "maennchen/zipstream-php",
@ -4190,16 +4189,16 @@
},
{
"name": "symfony/console",
"version": "v6.4.17",
"version": "v6.4.20",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "799445db3f15768ecc382ac5699e6da0520a0a04"
"reference": "2e4af9c952617cc3f9559ff706aee420a8464c36"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/799445db3f15768ecc382ac5699e6da0520a0a04",
"reference": "799445db3f15768ecc382ac5699e6da0520a0a04",
"url": "https://api.github.com/repos/symfony/console/zipball/2e4af9c952617cc3f9559ff706aee420a8464c36",
"reference": "2e4af9c952617cc3f9559ff706aee420a8464c36",
"shasum": ""
},
"require": {
@ -4264,7 +4263,7 @@
"terminal"
],
"support": {
"source": "https://github.com/symfony/console/tree/v6.4.17"
"source": "https://github.com/symfony/console/tree/v6.4.20"
},
"funding": [
{
@ -4280,7 +4279,7 @@
"type": "tidelift"
}
],
"time": "2024-12-07T12:07:30+00:00"
"time": "2025-03-03T17:16:38+00:00"
},
{
"name": "symfony/css-selector",
@ -4416,16 +4415,16 @@
},
{
"name": "symfony/error-handler",
"version": "v6.4.19",
"version": "v6.4.20",
"source": {
"type": "git",
"url": "https://github.com/symfony/error-handler.git",
"reference": "3d4e55cd2b8f1979a65eba9ab749d6466c316f71"
"reference": "aa3bcf4f7674719df078e61cc8062e5b7f752031"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/error-handler/zipball/3d4e55cd2b8f1979a65eba9ab749d6466c316f71",
"reference": "3d4e55cd2b8f1979a65eba9ab749d6466c316f71",
"url": "https://api.github.com/repos/symfony/error-handler/zipball/aa3bcf4f7674719df078e61cc8062e5b7f752031",
"reference": "aa3bcf4f7674719df078e61cc8062e5b7f752031",
"shasum": ""
},
"require": {
@ -4471,7 +4470,7 @@
"description": "Provides tools to manage errors and ease debugging PHP code",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/error-handler/tree/v6.4.19"
"source": "https://github.com/symfony/error-handler/tree/v6.4.20"
},
"funding": [
{
@ -4487,7 +4486,7 @@
"type": "tidelift"
}
],
"time": "2025-02-02T20:16:33+00:00"
"time": "2025-03-01T13:00:38+00:00"
},
{
"name": "symfony/event-dispatcher",
@ -4788,16 +4787,16 @@
},
{
"name": "symfony/http-kernel",
"version": "v6.4.19",
"version": "v6.4.20",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-kernel.git",
"reference": "88f2c9f7feff86bb7b9105c5151bc2c1404cd64c"
"reference": "6be6db31bc74693ce5516e1fd5e5ff1171005e37"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/88f2c9f7feff86bb7b9105c5151bc2c1404cd64c",
"reference": "88f2c9f7feff86bb7b9105c5151bc2c1404cd64c",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/6be6db31bc74693ce5516e1fd5e5ff1171005e37",
"reference": "6be6db31bc74693ce5516e1fd5e5ff1171005e37",
"shasum": ""
},
"require": {
@ -4882,7 +4881,7 @@
"description": "Provides a structured process for converting a Request into a Response",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/http-kernel/tree/v6.4.19"
"source": "https://github.com/symfony/http-kernel/tree/v6.4.20"
},
"funding": [
{
@ -4898,7 +4897,7 @@
"type": "tidelift"
}
],
"time": "2025-02-26T10:51:37+00:00"
"time": "2025-03-28T13:27:10+00:00"
},
{
"name": "symfony/mailer",
@ -5703,16 +5702,16 @@
},
{
"name": "symfony/process",
"version": "v6.4.19",
"version": "v6.4.20",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "7a1c12e87b08ec9c97abdd188c9b3f5a40e37fc3"
"reference": "e2a61c16af36c9a07e5c9906498b73e091949a20"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/7a1c12e87b08ec9c97abdd188c9b3f5a40e37fc3",
"reference": "7a1c12e87b08ec9c97abdd188c9b3f5a40e37fc3",
"url": "https://api.github.com/repos/symfony/process/zipball/e2a61c16af36c9a07e5c9906498b73e091949a20",
"reference": "e2a61c16af36c9a07e5c9906498b73e091949a20",
"shasum": ""
},
"require": {
@ -5744,7 +5743,7 @@
"description": "Executes commands in sub-processes",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/process/tree/v6.4.19"
"source": "https://github.com/symfony/process/tree/v6.4.20"
},
"funding": [
{
@ -5760,7 +5759,7 @@
"type": "tidelift"
}
],
"time": "2025-02-04T13:35:48+00:00"
"time": "2025-03-10T17:11:00+00:00"
},
{
"name": "symfony/routing",

333
config/excel.php

@ -0,0 +1,333 @@
<?php
use Maatwebsite\Excel\Excel;
return [
'exports' => [
/*
|--------------------------------------------------------------------------
| Chunk size
|--------------------------------------------------------------------------
|
| When using FromQuery, the query is automatically chunked.
| Here you can specify how big the chunk should be.
|
*/
'chunk_size' => 1000,
/*
|--------------------------------------------------------------------------
| Pre-calculate formulas during export
|--------------------------------------------------------------------------
*/
'pre_calculate_formulas' => false,
/*
|--------------------------------------------------------------------------
| Enable strict null comparison
|--------------------------------------------------------------------------
|
| When enabling strict null comparison empty cells ('') will
| be added to the sheet.
*/
'strict_null_comparison' => false,
/*
|--------------------------------------------------------------------------
| CSV Settings
|--------------------------------------------------------------------------
|
| Configure e.g. delimiter, enclosure and line ending for CSV exports.
|
*/
'csv' => [
'delimiter' => ',',
'enclosure' => '"',
'line_ending' => PHP_EOL,
'use_bom' => false,
'include_separator_line' => false,
'excel_compatibility' => false,
'output_encoding' => '',
'test_auto_detect' => true,
],
/*
|--------------------------------------------------------------------------
| Worksheet properties
|--------------------------------------------------------------------------
|
| Configure e.g. default title, creator, subject,...
|
*/
'properties' => [
'creator' => '',
'lastModifiedBy' => '',
'title' => '',
'description' => '',
'subject' => '',
'keywords' => '',
'category' => '',
'manager' => '',
'company' => '',
],
],
'imports' => [
/*
|--------------------------------------------------------------------------
| Read Only
|--------------------------------------------------------------------------
|
| When dealing with imports, you might only be interested in the
| data that the sheet exists. By default we ignore all styles,
| however if you want to do some logic based on style data
| you can enable it by setting read_only to false.
|
*/
'read_only' => true,
/*
|--------------------------------------------------------------------------
| Ignore Empty
|--------------------------------------------------------------------------
|
| When dealing with imports, you might be interested in ignoring
| rows that have null values or empty strings. By default rows
| containing empty strings or empty values are not ignored but can be
| ignored by enabling the setting ignore_empty to true.
|
*/
'ignore_empty' => false,
/*
|--------------------------------------------------------------------------
| Heading Row Formatter
|--------------------------------------------------------------------------
|
| Configure the heading row formatter.
| Available options: none|slug|custom
|
*/
'heading_row' => [
'formatter' => 'slug',
],
/*
|--------------------------------------------------------------------------
| CSV Settings
|--------------------------------------------------------------------------
|
| Configure e.g. delimiter, enclosure and line ending for CSV imports.
|
*/
'csv' => [
'delimiter' => null,
'enclosure' => '"',
'escape_character' => '\\',
'contiguous' => false,
'input_encoding' => 'UTF-8',
],
/*
|--------------------------------------------------------------------------
| Worksheet properties
|--------------------------------------------------------------------------
|
| Configure e.g. default title, creator, subject,...
|
*/
'properties' => [
'creator' => '',
'lastModifiedBy' => '',
'title' => '',
'description' => '',
'subject' => '',
'keywords' => '',
'category' => '',
'manager' => '',
'company' => '',
],
],
/*
|--------------------------------------------------------------------------
| Extension detector
|--------------------------------------------------------------------------
|
| Configure here which writer/reader type should be used when the package
| needs to guess the correct type based on the extension alone.
|
*/
'extension_detector' => [
'xlsx' => Excel::XLSX,
'xlsm' => Excel::XLSX,
'xltx' => Excel::XLSX,
'xltm' => Excel::XLSX,
'xls' => Excel::XLS,
'xlt' => Excel::XLS,
'ods' => Excel::ODS,
'ots' => Excel::ODS,
'slk' => Excel::SLK,
'xml' => Excel::XML,
'gnumeric' => Excel::GNUMERIC,
'htm' => Excel::HTML,
'html' => Excel::HTML,
'csv' => Excel::CSV,
'tsv' => Excel::TSV,
/*
|--------------------------------------------------------------------------
| PDF Extension
|--------------------------------------------------------------------------
|
| Configure here which Pdf driver should be used by default.
| Available options: Excel::MPDF | Excel::TCPDF | Excel::DOMPDF
|
*/
'pdf' => Excel::DOMPDF,
],
/*
|--------------------------------------------------------------------------
| Value Binder
|--------------------------------------------------------------------------
|
| PhpSpreadsheet offers a way to hook into the process of a value being
| written to a cell. In there some assumptions are made on how the
| value should be formatted. If you want to change those defaults,
| you can implement your own default value binder.
|
| Possible value binders:
|
| [x] Maatwebsite\Excel\DefaultValueBinder::class
| [x] PhpOffice\PhpSpreadsheet\Cell\StringValueBinder::class
| [x] PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder::class
|
*/
'value_binder' => [
'default' => Maatwebsite\Excel\DefaultValueBinder::class,
],
'cache' => [
/*
|--------------------------------------------------------------------------
| Default cell caching driver
|--------------------------------------------------------------------------
|
| By default PhpSpreadsheet keeps all cell values in memory, however when
| dealing with large files, this might result into memory issues. If you
| want to mitigate that, you can configure a cell caching driver here.
| When using the illuminate driver, it will store each value in the
| cache store. This can slow down the process, because it needs to
| store each value. You can use the "batch" store if you want to
| only persist to the store when the memory limit is reached.
|
| Drivers: memory|illuminate|batch
|
*/
'driver' => 'memory',
/*
|--------------------------------------------------------------------------
| Batch memory caching
|--------------------------------------------------------------------------
|
| When dealing with the "batch" caching driver, it will only
| persist to the store when the memory limit is reached.
| Here you can tweak the memory limit to your liking.
|
*/
'batch' => [
'memory_limit' => 60000,
],
/*
|--------------------------------------------------------------------------
| Illuminate cache
|--------------------------------------------------------------------------
|
| When using the "illuminate" caching driver, it will automatically use
| your default cache store. However if you prefer to have the cell
| cache on a separate store, you can configure the store name here.
| You can use any store defined in your cache config. When leaving
| at "null" it will use the default store.
|
*/
'illuminate' => [
'store' => null,
],
],
/*
|--------------------------------------------------------------------------
| Transaction Handler
|--------------------------------------------------------------------------
|
| By default the import is wrapped in a transaction. This is useful
| for when an import may fail and you want to retry it. With the
| transactions, the previous import gets rolled-back.
|
| You can disable the transaction handler by setting this to null.
| Or you can choose a custom made transaction handler here.
|
| Supported handlers: null|db
|
*/
'transactions' => [
'handler' => 'db',
'db' => [
'connection' => null,
],
],
'temporary_files' => [
/*
|--------------------------------------------------------------------------
| Local Temporary Path
|--------------------------------------------------------------------------
|
| When exporting and importing files, we use a temporary file, before
| storing reading or downloading. Here you can customize that path.
|
*/
'local_path' => storage_path('framework/cache/laravel-excel'),
/*
|--------------------------------------------------------------------------
| Remote Temporary Disk
|--------------------------------------------------------------------------
|
| When dealing with a multi server setup with queues in which you
| cannot rely on having a shared local temporary path, you might
| want to store the temporary file on a shared disk. During the
| queue executing, we'll retrieve the temporary file from that
| location instead. When left to null, it will always use
| the local path. This setting only has effect when using
| in conjunction with queued imports and exports.
|
*/
'remote_disk' => null,
'remote_prefix' => null,
/*
|--------------------------------------------------------------------------
| Force Resync
|--------------------------------------------------------------------------
|
| When dealing with a multi server setup as above, it's possible
| for the clean up that occurs after entire queue has been run to only
| cleanup the server that the last AfterImportJob runs on. The rest of the server
| would still have the local temporary file stored on it. In this case your
| local storage limits can be exceeded and future imports won't be processed.
| To mitigate this you can set this config value to be true, so that after every
| queued chunk is processed the local temporary file is deleted on the server that
| processed it.
|
*/
'force_resync_remote' => null,
],
];
Loading…
Cancel
Save