Reader speed

Topics: User Forum
Aug 16, 2011 at 2:24 PM

I was comparing Spreadsheet_Excel_Reader (2007) to PHPExcel for reading a 360 row excel document.

The former took .20seconds and the latter took 1.8s. Is there anything I can do to speed up performance of reading a document?

Here is PHP Excel code:

<?php

$time_start = microtime(true);

#########################################################################################################

include 'PHPExcel/Classes/PHPExcel.php';

/** PHPExcel_IOFactory - Reader */
include 'PHPExcel/Classes/PHPExcel/IOFactory.php';


$inputFileName = "file1.xls";  
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);  
$objReader = PHPExcel_IOFactory::createReader($inputFileType);  
$objReader->setReadDataOnly(true);  
$objPHPExcel = $objReader->load($inputFileName);  


$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();

$r = -1;
$namedDataArray = array();
for ($row = 1; $row <= $highestRow; ++$row) {
    $dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
    if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
        ++$r;
        echo 'Doing row #'. $r .'<br/>';
        //$namedDataArray[$r] = $dataRow[$row];
    }
}

#########################################################################################################

//echo '<pre>';
//var_dump($namedDataArray);
//echo '</pre><hr />';


$time_end = microtime(true);
$time = $time_end - $time_start;
echo '<br/>Took: '. $time .' seconds';
//average 1.8s


###############################################################################################################################################

Here is the Spreadsheet writer code:

###############################################################################################################################################

<?php

$time_start = microtime(true);
#########################################################################################################

include 'Spreadsheet_Excel_Reader/reader.php';

$inputFileName = "file1.xls";  
$reader = new Spreadsheet_Excel_Reader();
$reader->setOutputEncoding("UTF-8");
$reader->read($inputFileName);

# Traverse Rows

//$_CellValue = $_Reader->getRC($_Row, $_CellCol);
for ($i = 1; $i <= $reader->sheets[0]['numRows']; $i++) {
  for ($j = 1; $j <= $reader->sheets[0]['numCols']; $j++) {
    echo "\"".$reader->sheets[0]['cells'][$i][$j]."\",";
  }
  echo "\n";
}


####################################################################################

$time_end = microtime(true);
$time = $time_end - $time_start;
echo '<br/>Took: '. $time .' seconds';
//average .2s