This is my excel sheet
, it has a lot of columns but i'm upset to understand the question
I am reading an Excel worksheet using PHP Excel and using rangeToArray () which give me the whole row from excel, but I want the result to be like
Column as key: cell value as value
I am currently getting output as
Col index: cell value
So my question is, is this a function in Php Excel that returns an array with column name and cell value?
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
die('Error loading file"'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 2; $row <= $highestRow; $row++){
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE);
printArr($rowData);
printArr("-------");
}
I get output as
Array
(
[0] => Array
(
[0] => 27745186
[1] => 42058
[2] => DELL INTERNATIONAL SERVICES INDIA PVT LTD
...
...
)
[1] => Array
(
[0] => 27745186
[1] => 42058
[2] => DELL INTERNATIONAL SERVICES INDIA PVT LTD
...
...
)
)
Desired output
Array
(
[0] => Array
(
[Invoice_no] => 27745186
[Invoice Date] => 42058
[Description] => DELL INTERNATIONAL SERVICES INDIA PVT LTD
...
...
)
[1] => Array
(
[Invoice_no] => 27745186
[Invoice Date] => 42058
[Description] => DELL INTERNATIONAL SERVICES INDIA PVT LTD
...
...
)
)
source
share