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

Allow for selecting sheet by number #86

Merged
merged 4 commits into from May 11, 2022
Merged

Allow for selecting sheet by number #86

merged 4 commits into from May 11, 2022

Conversation

dakira
Copy link
Contributor

@dakira dakira commented May 10, 2022

This small (non-backwards-breaking) change allows for selecting the actual sheet to be read by the reader.

SimpleExcelReader::create('file.xlsx')
    ->take(5)
    ->fromSheet(2)
    ->getRows();

If you enter a sheetNumber that doesn't exist, the closest sheet will be used. An addition could be to throw an exception if the sheet doesn't exist, but I wanted to keep it as simple as possible.

@freekmurze
Copy link
Member

Could you throw an exception in that case by default, and add a test to prove that your code works?

@dakira
Copy link
Contributor Author

dakira commented May 11, 2022

Will do! :-)

@dakira
Copy link
Contributor Author

dakira commented May 11, 2022

@freekmurze There you go, hope this fits the standard. :-)

}

if ($this->sheetNumber !== $key) {
throw new InvalidArgumentException("Sheet {$key} does not exist in {$this->path}.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@freekmurze freekmurze merged commit c3afcaa into spatie:main May 11, 2022
@freekmurze
Copy link
Member

Thank you!

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