Running phpexcel only through selected columns

I have a huge sheet as my input, but I do not have to read all the columns, I need to read the selected columns only as B, H, I and J from 36 columns, and I will be very grateful for the full code, if some code also provided 4-5 lines. at the moment I am using the following code!

$objWorksheet = $objPHPExcel->setActiveSheetIndex('0') ; $i=0;$dum=false;$sum=0; foreach ($objWorksheet->getRowIterator() as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); if($dum) { // iterated. foreach ($cellIterator as $cell) { if($i==1||$i==7||$i==8||$i==9) { if($i==1) { $value[$i]=$cell->getValue(); $pieces = explode("_", $value[$i]); $asd=preg_split('#(?=\d)(?<=[az])#i',$pieces[0] ); // $value[$i]=$asd[1]; } if($i==7) { $value[$i]=PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'Ymd H:i:s'); $A=date('Ym-d', strtotime($value[$i])); $value[7]=$A; } if($i==8) { $value[$i]=PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'Ymd H:i:s'); ; $num2=$value[$i]; } if($i==9) { $value[$i]=$cell->getValue(); } echo $value[$i]; echo "|||||||"; }$i++; }$i=0; echo "<br>"; 
+4
source share
1 answer

Most likely it will be faster:

 $highestRow = $objWorksheet->getHighestRow(); for ($row = 0; $row <= $highestRow; ++$row) { // Fetch the data of the columns you need $col1 = $objWorksheet->getCellByColumnAndRow(1, $row)->getValue(); $col7 = $objWorksheet->getCellByColumnAndRow(7, $row)->getValue(); $col8 = $objWorksheet->getCellByColumnAndRow(8, $row)->getValue(); $col9 = $objWorksheet->getCellByColumnAndRow(9, $row)->getValue(); /* ** INSERT HERE YOUR PHP CODE */ echo $col1."||||||".$col7."||||||".$col8."||||||".$col9; } 
+5
source

All Articles