-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Se ha implementado PHPSpreadSheet con exito, se ha creado clase exclu…
…siva para el trabajo de funciones de excel dentro del framework.
- Loading branch information
Showing
6 changed files
with
756 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
namespace App\Http\Functions; | ||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; | ||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
use PhpOffice\PhpSpreadsheet\Reader\Xls; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; | ||
use PhpOffice\PhpSpreadsheet\Style\Fill; | ||
use PhpOffice\PhpSpreadsheet\Style\Color; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; | ||
use App\Http\Functions\Files; | ||
|
||
|
||
class Excel { | ||
|
||
private static Spreadsheet $spreadsheet; | ||
private static Worksheet $worksheet; | ||
private static array $list_push = []; | ||
|
||
public function __construct() { | ||
|
||
} | ||
|
||
public static function info(): array { | ||
return self::$list_push; | ||
} | ||
|
||
public static function new(string $path, string $file_name): string { | ||
Files::folder($path); | ||
$file_name = Files::rename("{$file_name}.xlsx"); | ||
(new Xlsx(new Spreadsheet()))->save("{$path}{$file_name}"); | ||
return $file_name; | ||
} | ||
|
||
public static function load(string $path): void { | ||
self::$spreadsheet = IOFactory::createReader("Xlsx")->load($path); | ||
self::$worksheet = self::$spreadsheet->getActiveSheet(); | ||
} | ||
|
||
public static function merge(string $columns): void { | ||
self::$worksheet->mergeCells($columns); | ||
} | ||
|
||
public static function image(string $column, string $path, ?int $height = null): void { | ||
$drawing = new Drawing(); | ||
$drawing->setCoordinates($column); | ||
$drawing->setPath($path); | ||
if ($height != null) $drawing->setHeight($height); | ||
$drawing->setWorksheet(self::$worksheet); | ||
} | ||
|
||
public static function size(string $columns, int $size): void { | ||
self::$worksheet->getStyle($columns)->getFont()->setSize($size); | ||
} | ||
|
||
public static function bold(string $column): void { | ||
self::$worksheet->getStyle($column)->getFont()->setBold(true); | ||
} | ||
|
||
public static function color(string $column, string $color): void { | ||
self::$worksheet->getStyle($column)->getFont()->getColor()->setARGB($color); | ||
} | ||
|
||
public static function background(string $column, string $color, ?string $type_color = null): void { | ||
if (strtoupper($type_color) === 'FILL_SOLID') { | ||
$setType = Fill::FILL_SOLID; | ||
} elseif (strtoupper($type_color) === 'FILL_GRADIENT_LINEAR') { | ||
$setType = Fill::FILL_GRADIENT_LINEAR; | ||
} else { | ||
$setType = Fill::FILL_SOLID; | ||
} | ||
|
||
self::$worksheet->getStyle($column)->getFill()->setFillType($setType)->getStartColor()->setARGB($color); | ||
} | ||
|
||
public static function insert(int $number): void { | ||
self::$worksheet->insertNewRowBefore($number); | ||
} | ||
|
||
public static function push(string $value, string $char): void { | ||
self::$list_push[$char] = $value; | ||
} | ||
|
||
public static function add(string $index = null, string $value = null): void { | ||
if ($index != null && $value != null) { | ||
self::$worksheet->setCellValue($index, self::replace($value)); | ||
} else { | ||
foreach (self::$list_push as $key => $cell) { | ||
self::$worksheet->setCellValue(((string) $key), self::replace($cell)); | ||
} | ||
} | ||
} | ||
|
||
public static function save(string $path, string $file_name): string { | ||
$file_name = Files::rename("{$file_name}.xlsx"); | ||
(new Xlsx(self::$spreadsheet))->save("{$path}{$file_name}"); | ||
return $file_name; | ||
} | ||
|
||
private static function replace($cell): string { | ||
$cell = str_replace("á", "á", $cell); | ||
$cell = str_replace("é", "é", $cell); | ||
$cell = str_replace("í", "í", $cell); | ||
$cell = str_replace("ó", "ó", $cell); | ||
$cell = str_replace("ú", "ú", $cell); | ||
$cell = str_replace("ñ", "ñ", $cell); | ||
$cell = str_replace("á", "á", $cell); | ||
$cell = str_replace("é", "é", $cell); | ||
$cell = str_replace("Ã", "í", $cell); | ||
$cell = str_replace("ó", "ó", $cell); | ||
$cell = str_replace("ú", "ú", $cell); | ||
$cell = str_replace("ñ", "ñ", $cell); | ||
$cell = str_replace("Ã", "á", $cell); | ||
$cell = str_replace("É", "é", $cell); | ||
$cell = str_replace("Ã", "í", $cell); | ||
$cell = str_replace("Ó", "ó", $cell); | ||
$cell = str_replace("Ú", "ú", $cell); | ||
$cell = str_replace("Ñ", "ñ", $cell); | ||
$cell = str_replace("á", "á", $cell); | ||
$cell = str_replace("é", "é", $cell); | ||
$cell = str_replace("í", "í", $cell); | ||
$cell = str_replace("ó", "ó", $cell); | ||
$cell = str_replace("ú", "ú", $cell); | ||
$cell = str_replace("ñ", "ñ", $cell); | ||
return $cell; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.