Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read first row without createRowIterator? #50

Open
mystackover opened this issue Jun 18, 2017 · 1 comment
Open

How to read first row without createRowIterator? #50

mystackover opened this issue Jun 18, 2017 · 1 comment

Comments

@mystackover
Copy link

I would like to read first row without createRowIterator interface as first line, in XLSX file, belongs to my database table fields. So I would like to read them first and want to put it in fields array.

I am using your sample code at first level:
use Akeneo\Component\SpreadsheetParser\SpreadsheetParser;
use Akeneo\Component\SpreadsheetParser\Xlsx\XlsxParser;

$workbook = SpreadsheetParser::open('myfile.xlsx');
$myWorksheetIndex = $workbook->getWorksheetIndex('sheet1');

//MY REQUIREMENT
//Here I want to get first row as they will be treated as my table fields.

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

Any help would be appreciated.

Thanks, Sumit

@Kryptonit3-zz
Copy link

$workbook = SpreadsheetParser::open('myfile.xlsx');
$myWorksheetIndex = $workbook->getWorksheetIndex('sheet1');

$headers = [];

foreach ($workbook->createRowIterator($myWorksheetIndex) as $rowIndex => $values) {
    // Get headers
    if ($rowIndex == 1) {
        $headers = $values;
    }

    // All other rows
    if ($rowIndex > 1) {
        //
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants