Good evening.
I'm in the following situation: I'm reading an XLS and playing in a table. This XLS has 52 rows and 6 columns.
What I'm getting caught up to do is:
$result[linha 1][coluna A]
$result[linha 1][coluna B]
$result[linha 1][coluna C]
$result[linha 1][coluna D]
$result[linha 1][coluna E]
$result[linha 1][coluna F]
$result[linha 2][coluna A]
$result[linha 2][coluna B]
$result[linha 2][coluna C]
$result[linha 2][coluna D]
$result[linha 2][coluna E]
$result[linha 2][coluna F]
$result[linha 3][coluna A]
$result[linha 3][coluna B]
$result[linha 3][coluna C]
$result[linha 3][coluna D]
$result[linha 3][coluna E]
$result[linha 3][coluna F]
And so on.
How do I compose this loop? I'm trying with for and while, but it's not rolling. I thought about doing with foreach, but I do not think this option will do. I'm really lost on how to execute this loop inside loop.
Below is my code. NOTE: I am using the PHPExcel lib to read:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once dirname(__FILE__) . '/inc/PHPExcel.php';
$fileName = 'file.xls';
$excelReader = PHPExcel_IOFactory::createReaderForFile($fileName);
$excelReader->setReadDataOnly();
$excelReader->setLoadAllSheets();
$excelObj = $excelReader->load($fileName);
$excelObj->getActiveSheet()->toArray(null, true,true,true);
$worksheetNames = $excelObj->getSheetNames($fileName);
$return = array();
foreach( $worksheetNames as $key => $sheetName ){
$excelObj->setActiveSheetIndexByName($sheetName);
$return[$sheetName] = $excelObj->getActiveSheet()->toArray(null, true,true,true);
}
$totalRows = count($return['Sheet0']);
$columns = range('A','F');
$colNum = 0;
$rowNum = 1;
$maxCol = 1;
echo '<table class="table table-responsive">';
echo '<thead>';
echo '<th>';
while ( $colNum < count($columns) ) {
echo '<td>' . $return['Sheet0'][11][ $columns[ $colNum ] ] . '</td>';
$colNum++;
}
echo '<th>';
echo '</thead>';
echo '<tbody>';
echo '<tr>';
for ( $a=1; $a<=$totalRows; $a++ ) {
if ( $rowNum <= 6 ) {
echo "return['Sheet0'][". $a . "][columns[" . $rowNum . "] ] " . EOL;
//echo '</tr><tr>';
}
$rowNum++;
}
echo '</tr>';
echo '</tbody>';
echo '</table>';
Thank you