How do I get just one row from a specific column? In the code below it shows me all the rows and all the columns it has in the CSV file. I just want a specific cell.
Example:
Coluna B - Cars
Line 2 - Fox
Line and column cell - B2
I want to get only this B2 cell and print it on the screen.
<?php
// activar Error reporting
error_reporting(E_ALL);
// carregar a classe PHPExcel
require_once 'Classes/PHPExcel.php';
// iniciar o objecto para leitura
$objReader = new PHPExcel_Reader_CSV();$objReader->setInputEncoding('CP1252');
$objReader->setDelimiter(';');
$objReader->setEnclosure('');
$objReader->setSheetIndex(0);
$objPHPExcel = $objReader->load("itens.csv");
//Pegando o total de colunas
$colunas = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
$total_colunas = PHPExcel_Cell::columnIndexFromString($colunas);
//Pegando o total de linhas
$total_linhas = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
echo "<table border='1'>";
// navegar na linha
for($linha=1; $linha<= $total_linhas; $linha++){
echo "<tr>";
// navegar nas colunas da respactiva linha
for($coluna=1; $coluna<= $total_colunas -1; $coluna++){
if($linha==1){
// escreve o cabeçalho da tabela
echo "<th>".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue())."</th>";
}else{
// escreve os dados da tabela
echo "<td>".utf8_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($coluna, $linha)->getValue())."</td>";
}
}
echo "</tr>";
}
echo "</table>";
?>