0
How do I pick up only one row of a specific column? In the code below it shows me all the rows and all the columns you have in the CSV file. I just want a specific cell.
Example:
Column B - Cars
Line 2 - Fox
Row and column cell - B2
I want to take just this cell B2 and print it on 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>";
?>
In case, you just did the
for
to generate the table from the CSV, correct? How do you describe how you tried to get only this cell? It could just be a description of logic if you don’t know what the code is.– Woss
I guess I didn’t get it. I’m not just taking a cell, I took everything that was in the CSV file. I want to take only 1 cell. which in my file is called AI2.
– Alexandre Amado
That’s what I said. Your code in the question is taking all the content and generating an HTML table, but has no attempt to find just the desired cell. You even tried to do something about it?
– Woss
Oh yes. No, I do not know how it does it. So I came here to ask, I do not know that it generates only one cell, I only know how to generate the whole table.
– Alexandre Amado