Reputation: 795
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.
Upvotes: 0
Views: 35
Reputation: 153
There is nothing really wrong with your code, But you can check the current format in the excel. I guess the date in your excel data is in text format , not the date format you should change the excel format.
Upvotes: 1