Initial import
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: W10
|
||||
* Date: 2/17/2021
|
||||
* Time: 3:24 PM
|
||||
*/
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
use app\extensions\simplex\SimpleXLSX;
|
||||
use app\extensions\XLSXWriter;
|
||||
use app\extensions\XLSXReader;
|
||||
|
||||
class XLSx
|
||||
{
|
||||
public static function toXlsWriter($data, $fileName, $sheet, $header)
|
||||
{
|
||||
$headerRow = [];
|
||||
foreach ($header as $headerTitle => $headerElement) $headerRow[] = $headerTitle;
|
||||
|
||||
$filename = $fileName . '.csv';
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
$dataAsString = implode(';', $headerRow) . "\r\n";
|
||||
foreach ($data as $row) {
|
||||
$dataAsString .= implode(';', $row) . "\r\n";
|
||||
}
|
||||
echo $dataAsString;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
public static function toArrayWriter($targetFile, $sheet)
|
||||
{
|
||||
try {
|
||||
$xlsx = new XLSXReader($targetFile);
|
||||
return $xlsx->getSheetData($sheet);
|
||||
} catch (\Exception $e) {
|
||||
return ['error' => 'The Sheet not exists in this file'];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user