-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
415 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
/** | ||
* Description of ExcelFile | ||
* | ||
* @author agottardi | ||
*/ | ||
|
||
namespace CSVMapper\Source; | ||
|
||
use PHPExcel_IOFactory; | ||
use PHPExcel_Cell; | ||
|
||
class ExcelFile extends File { | ||
|
||
private $rowNumber = 1; | ||
|
||
public function getColumnsAllowed() { | ||
if (empty($this->columnsAllowed)) { | ||
return FALSE; | ||
} else { | ||
return $this->columnsAllowed; | ||
} | ||
} | ||
|
||
public function setColumnsAllowed($columnsAllowed) { | ||
$this->columnsAllowed = $columnsAllowed; | ||
} | ||
|
||
public function openFile($path) { | ||
$inputFileName = $path; | ||
/** Identify the type of $inputFileName * */ | ||
$inputFileType = PHPExcel_IOFactory::identify($inputFileName); | ||
/** Create a new Reader of the type that has been identified * */ | ||
$objReader = PHPExcel_IOFactory::createReader($inputFileType); | ||
/** Load $inputFileName to a PHPExcel Object * */ | ||
$objPHPExcel = $objReader->load($inputFileName); | ||
$this->rowNumber = 1; | ||
return $objPHPExcel; | ||
} | ||
|
||
public function getFileColumns() { | ||
$objPHPExcel = $this->getHandler(); | ||
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0); | ||
$highestColumn = $objWorksheet->getHighestColumn(); | ||
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); | ||
return $highestColumnIndex-1; | ||
} | ||
|
||
public function getRawRow() { | ||
|
||
$values = array(); | ||
$objPHPExcel = $this->getHandler(); | ||
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0); | ||
$highestColumnIndex = $this->getFileColumns(); | ||
|
||
|
||
for ($col = 0; $col <= $highestColumnIndex; $col++) { | ||
|
||
$cell = $objWorksheet->getCellByColumnAndRow($col, $this->rowNumber); | ||
$cellValue = $cell->getValue(); | ||
|
||
array_push($values, $cellValue); | ||
} | ||
|
||
$this->rowNumber++; | ||
|
||
return $values; | ||
} | ||
|
||
public function hasRow() { | ||
|
||
$objPHPExcel = $this->getHandler(); | ||
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0); | ||
|
||
$highestRow = $objWorksheet->getHighestRow(); // e.g 'F' | ||
|
||
if ($highestRow == 1 && $objWorksheet->getCellByColumnAndRow(0, 1)->getValue() == null) { | ||
return false; | ||
} else if ($highestRow >= $this->rowNumber) { | ||
return true; | ||
} else if ($highestRow < $this->rowNumber) { | ||
return false; | ||
} | ||
} | ||
|
||
public function reset() { | ||
$this->rowNumber = 1; | ||
} | ||
|
||
public function getHighestColumnIndex() | ||
{ | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.