From a3cf27b3675120afc066c78842ebb52bfb46d4ad Mon Sep 17 00:00:00 2001 From: RAJKUMAR SAMRA Date: Wed, 7 Aug 2024 23:51:55 +0530 Subject: [PATCH] init --- .gitignore | 3 ++- src/ExcelTo.php | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5657f6e..82a1a89 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -vendor \ No newline at end of file +vendor +.vscode \ No newline at end of file diff --git a/src/ExcelTo.php b/src/ExcelTo.php index 5b27c73..57c6628 100644 --- a/src/ExcelTo.php +++ b/src/ExcelTo.php @@ -8,7 +8,6 @@ class ExcelTo { - public static function json($filePath) { $spreadsheet = IOFactory::load($filePath); @@ -49,6 +48,25 @@ public static function collection($filePath) return $collection; } + public static function array($filePath) + { + $spreadsheet = IOFactory::load($filePath); + $sheetCount = $spreadsheet->getSheetCount(); + $arrayData = []; + + foreach ($spreadsheet->getAllSheets() as $worksheet) { + $sheetData = self::processSheet($worksheet); + + if ($sheetCount > 1) { + $arrayData[$worksheet->getTitle()] = $sheetData; + } else { + $arrayData = $sheetData; + } + } + + return $arrayData; + } + private static function processSheet($worksheet) { $excelData = $worksheet->toArray();