Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value by column name in php spreadsheet-parser library?

I'm using akeneo-labs spreadsheet-parser library to extract data from xlsx file.

use Akeneo\Component\SpreadsheetParser\SpreadsheetParser;

$workbook = SpreadsheetParser::open('myfile.xlsx');

$myWorksheetIndex = $workbook->getWorksheetIndex('myworksheet');

foreach ($workbook->createRowIterator($myWorksheetIndex) as $rowIndex => $values) {
    var_dump($rowIndex, $values);
}

Actually, you can get value by column index in a loop, is it possible to get value by column name instead?

like image 408
Zeta Avatar asked Nov 24 '25 13:11

Zeta


2 Answers

maybe using another package as suggested fixes your problem. also you can use array_column https://www.php.net/manual/en/function.array-column.php

like image 152
Moaaz Avatar answered Nov 26 '25 04:11

Moaaz


Maybe you can do that in a spreadsheet CSV file by using PHP default function fgetcsv(), you can go throw an overview from here: https://www.php.net/manual/en/function.fgetcsv fgetcsv — Gets line from file pointer and parse for CSV fields

First of all, save as your Xls file in CSV type then you can take your value from that CSV file by column name.

like image 32
Ahm Harunur Rashid Avatar answered Nov 26 '25 03:11

Ahm Harunur Rashid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!