我正在尝试只读取所有行的1,3,6和7列。我试过这样但是不起作用。
$objPHPExcel = PHPExcel_IOFactory::load($file);
$sheet = $objPHPExcel->getSheetByName('Prefixes');
$i =2;
foreach($sheet->getRowIterator() as $row){
$dest = $sheet->getCellByColumnAndRow(1, $i)->getValue();
$code = $sheet->getCellByColumnAndRow(3, $i)->getValue();
$price = trim($sheet->getCellByColumnAndRow(6,$i)->getCalculatedValue());
$date = date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($sheet->getCellByColumnAndRow(7,$i)->getCalculatedValue()));
$rateSheet[] = array($dest,$code,$price,$date);
$i++;
}
答案 0 :(得分:0)
如果它可以帮助某人这是正确的方式:
$rateSheet=array();
$objPHPExcel = PHPExcel_IOFactory::load($file);
if($file=="519340.xls"){
echo "</br>OK</br>";
$sheet = $objPHPExcel->getSheetByName('Prefixes');
$i =2;
$highestRow=$objPHPExcel->setActiveSheetIndex(1)->getHighestRow();
echo $highestRow;
for($j=0;$j<$highestRow;$j++){
$dest = $sheet->getCellByColumnAndRow(0, $i)->getValue();
$code = $sheet->getCellByColumnAndRow(2, $i)->getValue();
$price = trim($sheet->getCellByColumnAndRow(5,$i)->getCalculatedValue());
$date = date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($sheet->getCellByColumnAndRow(6,$i)->getCalculatedValue()));
$rateSheet[] = array($dest,$code,$price,$date);
$i++;
}
return $rateSheet;