<?php

require './vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$excelData = array();
$file = "./assets/excels/公司人員資料.xlsx";

$extension = pathinfo($file, PATHINFO_EXTENSION);

if ('csv' == $extension) {
    $reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
} else if ('xls' == $extension) {
    $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
} else{
    $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
}
$reader->setReadDataOnly(true);
$reader->setReadEmptyCells(false);
$spreadsheet = $reader->load($file);
$sheetCount = $spreadsheet->getSheetCount();
$all = $spreadsheet->getSheetNames();

for ($s = 0; $s < $sheetCount; $s++) {
    $data = array();
    $sheet = $spreadsheet->getSheet($s);
    $sheetName = $spreadsheet->getSheetNames()[$s];
    $cellCollection = $sheet->getCellCollection();
    $column = $cellCollection->getHighestRowAndColumn();    
    for ($i = 1; $i <= $column['row']; $i++) { //行        
        $row = array();
        for ($j = 'A'; $j <= $column['column']; $j++) { //列
            $key = $j . $i;
            $value = $sheet->getCell($key)->getValue();
            
            array_push($row, $value);
        }
        array_push($data, $row);
    }
    $excelData[$sheetName] = $data;
}
