-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Your requested sheet index: -1 is out of bounds. The actual number of sheets is 1 #4112
Comments
Confirmed, introduced with 2.2. Researching. |
I see the problem and am working on a solution. As a workaround, you can add the following line after $mySpreadsheet->setActiveSheetIndex(0); I think addSheet probably ought to set the Active Sheet anyhow when there is no other sheet in the workbook. |
Better workaround - don't specify sheet number 0 on your addSheet. This will cause Active Sheet to be set to the new sheet automatically if it's the only sheet: $mySpreadsheet->addSheet($worksheet); |
Fix PHPOffice#4112. Direct cause is that `applyStylesFromArray` tries to save and restore `activeSheetIndex`. However, if activeSheetIndex is -1, indicating no active sheet, the restore should not be attempted. Code is changed to test before attempting to restore. The actual problem, however, is that user specified a sheet number for `addSheet`. That method will set activeSheetIndex most of the time, but this was a gap - when the supplied sheet number (0 in this case) is greater than activeSheetIndex (-1 in this case), it was leaving activeSheetIndex as -1. It is changed to set activeSheetIndex to 0 when activeSheetIndex is negative.
This is:
What is the expected behavior?
not throwing an Exception ?
What is the current behavior?
[Exception]
HTTP 500 Internal Server Error
Your requested sheet index: -1 is out of bounds. The actual number of sheets is 1.
What are the steps to reproduce?
What features do you think are causing the issue
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 2.2 / PHP 8.3
The text was updated successfully, but these errors were encountered: