mercredi 25 mars 2015

Generate a matrix from an excel worksheet [ExcelBundle-Symfony]

I made the follow function for get a matrix from a worksheet.



private function getMatrixFromSheet($worksheet){
foreach ($worksheet->getRowIterator() as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
if (!is_null($cell)) {
$matrix[$cell->getRow()][$cell->getColumn()] = $cell->getCalculatedValue();
}
}
}
return $matrix;
}


In this way if I want to access to the second row, second col cell, I can do $matrix[2]['B'].


I need to be able to access to the matrix indexes both as number in order to access to the previous cell as $matrix[2][2].


Is there a way to do this?

I try to convert $cell->getColumn() result in a integer, but unfortunately (int) "a" == 0


Aucun commentaire:

Enregistrer un commentaire