Giter VIP home page Giter VIP logo

Comments (5)

adrilo avatar adrilo commented on May 27, 2024

Hi,
As described in the doc, you should not call next() directly:

foreach ($reader->getSheetIterator() as $sheet) {
    foreach ($sheet->getRowIterator() as $row) {
        // do stuff with the row
        $cells = $row->getCells();
        ...
    }
}

from spout.

Sukushi avatar Sukushi commented on May 27, 2024

the fact is that I want to do a different thing only for the first line (get the index name and position of the column) and then treat the row with the foreach.
there is no way to use next() directly ?

I bypass the problem like this but this isn't a satisfying solution.

$boolIndex = true;

foreach ($rows as $row) {
    if ($boolIndex) {
        // do thing for the first line
        $boolIndex = false;
    } 
    else {
        // do thing for the row
    }
}

from spout.

adrilo avatar adrilo commented on May 27, 2024

(we can continue the discussion here)

foreach ($sheet->getRowIterator() as $rowIndex => $row) {
    if ($rowIndex === 0) {
      // do something with the first row
    } else {
    }
}

This is how it should be done

from spout.

Sukushi avatar Sukushi commented on May 27, 2024

(I was not sure if you will see it)
Yes thanks that a better solution.
I see somewhere that next() was available but you remove it, why ? in that sort of case it's still more clean (I think) to do it with the next().

from spout.

adrilo avatar adrilo commented on May 27, 2024

next() is technically still present (see https://github.com/box/spout/blob/master/src/Spout/Reader/XLSX/RowIterator.php#L179-L186). However I don't guarantee that the implementation is 100% compliant with what's expected. I had to do a few hacks to get the streaming part working. I can guarantee that the foreach approach works, but can't for the hasNext/next/current approach

from spout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.