Count columns and rows when reading .xls

Topics: Developer Forum, Project Management Forum, User Forum
May 11, 2010 at 7:37 PM

Hi guys many thanks for this magnificent API, since i am a CS student i need a little help. I haven't found till now how to count the number of columns and rows when i read a .xls file.

I use something like the following

require_once '../Classes/PHPExcel.php';

/** PHPExcel_IOFactory */
require_once '../Classes/PHPExcel/IOFactory.php';
$file='C:\wamp\www\uploads\a.xls';
//$objReader = new PHPExcel_Reader_Excel5();
$objReader =PHPExcel_IOFactory::createReaderForFile($file);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file);

$objPHPExcel->setActiveSheetIndex(0);
//$sheet = $objPHPExcel->getActiveSheet();
$a=$objPHPExcel->getActiveSheet()->getHighestColumn();
$objPHPExcel->getActiveSheet()->getHighestRow();  

I tried getSheetIndex() but no effect.
Also i need
with a loop like foreach or for($i=0; $i<=$NoCols), to use the values (names of xls columns) in a create stetement as the names of fields for the db table.
Any help would be greatly appreciated, thanks in advance!

 

Coordinator
May 15, 2010 at 11:09 AM

I'm not sure I really understand what you're asking, but take a look at the row and column iterators (example code in /Tests/28iterator.php)