I'm using CodeIgniter and PHPExcel to make a system. Here I have the loop and return function in ExcelModel to loop in columns and rows I want:
$lastColumn = $objWorksheet->getHighestColumn();
$lastColumn++;
$cell = array();
for ($row = 2; $row <= 7; $row++) {
for($column = 'A'; $column != $lastColumn; $column++) {
$cell[] = $objWorksheet->getCell($column.$row)->getValue();
}
}
return $cell;
My view is receiving the data, everything is fine. But, I want to build a HTML table with the data, but the problem is: that array didn't have a key writed by me, so in my table when I output the variable inside tags, it comes the same thing. Look:
foreach ($excelData as $dataArray) {
echo '<tr>';
echo '<td>' . $dataArray . '</td>';
echo '<td>' . $dataArray . '</td>';
echo '<td>' . $dataArray . '</td>';
echo '<td>' . $dataArray . '</td>';
echo '<td>' . $dataArray . '</td>';
echo '</tr>';
}
I know that if I have something like this:
foreach ($excelData as $dataArray) {
echo '<tr>';
echo '<td>' . $dataArray['example1'] . '</td>';
echo '<td>' . $dataArray['example2'] . '</td>';
echo '<td>' . $dataArray['example3'] . '</td>';
echo '<td>' . $dataArray['example4'] . '</td>';
echo '<td>' . $dataArray['example5'] . '</td>';
echo '</tr>';
}
It'd work. But, as my array is empty and is filled after the loop in ExcelModel, how can I make this?