This commit is contained in:
salam committed 2026-09-27 17:34:34 +02:00
1 parent 6662b0a823
commit 750b8bc571
3 files changed
+37 -30

No files matched your search

+20 -15
View File
@@ -9,9 +9,11 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
trait GrappingToExcel
{
public static $max = 2000;
protected int $max = 2000;
public function import_to_excel(string $folder, $title = '')
protected string $titel = '';
public function import_to_excel(string $folder, $day = '')
{
ini_set('memory_limit', -1);
@@ -19,35 +21,38 @@ trait GrappingToExcel
Notice::note("import $folder to excel", 'g');
}
if (! $title) {
$titel = ucfirst($folder).'_'.Carbon::now()->format('Y-m-d');
$this->titel = ucfirst($folder);
if (! $day) {
$this->titel .= '_'.Carbon::now()->format('Y-m-d');
} else {
$this->titel .= "_$day";
}
$files = $this->get_tree("$this->data_dir/$folder");
$files = $this->get_tree($this->data_dir);
$files = array_chunk($this->filter($files), self::$max);
$files = array_chunk($this->filter($files), $this->max);
foreach ($files as $key => $value) {
$has = count($value);
if (! $key && $has < self::$max) {
if (! $key && $has < $this->max) {
$count_from = 1;
$count_to = $has;
} elseif (! $key) {
$count_from = 1;
$key++;
$count_to = $key * self::$max;
} elseif ($has == self::$max) {
$count_from = $key * self::$max + 1;
$count_to = $key * $this->max;
} elseif ($has == $this->max) {
$count_from = $key * $this->max + 1;
$key++;
$count_to = $key * self::$max;
$count_to = $key * $this->max;
} else {
$count_from = $key * self::$max + 1;
$count_to = $key * self::$max + $has;
$count_from = $key * $this->max + 1;
$count_to = $key * $this->max + $has;
}
$spreadsheet = new Spreadsheet;
$spreadsheet->getProperties()->setTitle("$title-$count_from-$count_to");
$spreadsheet->getProperties()->setTitle($this->titel.'-'.$count_from.'-'.$count_to);
$activeWorksheet = $spreadsheet->getActiveSheet();
$column = 1;
@@ -69,7 +74,7 @@ trait GrappingToExcel
$spreadsheet->setActiveSheetIndex(0);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save("$this->data_dir/$folder/$titel-$count_from-$count_to.xlsx");
$writer->save("$this->data_dir/$folder/$this->titel-$count_from-$count_to.xlsx");
}
}