PHP数组excel上传得到奇怪的结果

伙计们! 我需要一些我的代码的帮助,为什么我的数组结果在Excel上传得到一个空值? 我跟踪代码并debugging它,但仍然没有任何东西。

这是我的Excel数据:

Title ======================================================================================================= |Region |Branch Id | Agent Code | Cabang | Policy No | Policy Holder | Remark |Date | ======================================================================================================= |NYC | | 12345 | BG 3 | 3003659123 | YU KERY | Remark | 15-05-2017 | |JKT | | 54321 | BG 3 | 3003822124 | PRAWINDRA IRAWAN | Remark | 30-12-2016 | ======================================================================================================= 

我只是想从代理代码中获取数据,但在debugging那里的空数组数据,也得到了奇怪的date。

  [0] => Array ( [0] => 12345 [1] => NYC [2] => 3003659123 [3] => YU KERY [4] => Remark [5] => 42870 ? [6] => ??? ) 

这里是我的代码来获取Excel数据:

  for ($h = 0; $h <= PHPExcel_Cell::columnIndexFromString($objPHPExcel->getActiveSheet()->getHighestColumn()); $h++) if(trim($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($h,2)->getValue())) $headerText['sheet0'][] = strtoupper($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($h,2)->getValue()); // get header or field name $startRow = 3; for ($i = $startRow; $i <= $objPHPExcel->getActiveSheet()->getHighestRow(); $i++) { $dataRow = array(); for ($j = 2; $j <= count($headerText['sheet0']); $j++) { $region = strtolower($objPHPExcel->getActiveSheet()->getCellByColumnAndRow(0,$i)->getValue()); $branch = strtolower($objPHPExcel->getActiveSheet()->getCellByColumnAndRow(1,$i)->getValue()); if ($region != null) { $dataRow[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$i)->getValue(); if(!in_array($region,$arrNPK) && !empty($region)) $arrNPK[] = $region; } elseif ($region == null && $branch != null) { $dataRow[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$i)->getValue(); if(!in_array($branch,$arrNPK) && !empty($branch)) $arrNPK[] = $branch; } } $arrResult['sheet0'][$region][] = $dataRow; $arrResult['sheet0'][$branch][] = $dataRow; print_r($arrResult);exit(); } 

为什么我做$ region和$ branch是因为有时候用户,在excel中只填写其中的一个。

你的代码没有什么问题,但是你可以在excel中检查当前的格式。 我想你的Excel数据中的date是文本格式,而不是date格式,你应该改变Excel格式。