guys! I need some help of my code,why are my array result on excel upload is get a null value? I'm trace the code and debug it but still got nothing.
Here's my excel data:
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 |
=======================================================================================================
I just want get the data start from agent code,but after debug the there null array data and also got strange date too.
[0] => Array
(
[0] => 12345
[1] => NYC
[2] => 3003659123
[3] => YU KERY
[4] => Remark
[5] => 42870 ?
[6] => ???
)
Here's my code to get the excel data:
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();
}
why i made $region and $branch is because sometimes users,only fill one of them in excel.
$j <= PHPExcel_Cell::columnIndexFromString($objPHPExcel->getActiveSheet()->getHighestColumn())-1;andif(!in_array($region,$arrNPK) && !empty($region)) $arrNPK[] = $region; if($j==7 ) $dataRow[] = PHPExcel_Style_NumberFormat::toFormattedString($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$i)->getCalculatedValue(),'DD-MMM-YYYY'); else $dataRow[] = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$i)->getValue();