Skip to content

Commit

Permalink
Merge pull request #8 from Knackline/feature/excel-to-array
Browse files Browse the repository at this point in the history
Feature/excel to array
  • Loading branch information
rjsamra authored Aug 7, 2024
2 parents 90e726d + a3cf27b commit 8f54601
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor
vendor
.vscode
20 changes: 19 additions & 1 deletion src/ExcelTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class ExcelTo
{

public static function json($filePath)
{
$spreadsheet = IOFactory::load($filePath);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8f54601

Please sign in to comment.