-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExcelReader.php
42 lines (38 loc) · 1.08 KB
/
ExcelReader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace boundstate\importexport;
use PHPExcel;
use PHPExcel_IOFactory;
use PHPExcel_Shared_Date;
/**
* Reads Excel files using PHPExcel.
* @package boundstate\importexport
*/
class ExcelReader extends BaseReader
{
/**
* Reads from an Excel file.
* @param string $filename
*/
protected function read($filename)
{
$reader = PHPExcel_IOFactory::createReaderForFile($filename);
$xl = $reader->load($filename);
/* @var $xl \PHPExcel */
$sheet = $xl->getActiveSheet();
$this->rows = [];
foreach ($sheet->getRowIterator() as $row) {
$dataRow = [];
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
if (PHPExcel_Shared_Date::isDateTime($cell)) {
// Convert Excel representations of dates to yyyy-MM-dd format
$dataRow[] = gmdate('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($cell->getValue()));
} else {
$dataRow[] = $cell->getValue();
}
}
$this->rows[] = $dataRow;
}
}
}