-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Last Sheet is alway set as the Active Sheet upon loading the File #2666
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
Comments
+1 |
What version of PhpSpreadsheet? And what file formats are affected? And if you have a sample file that demonstrates this problem, that would be useful. I've created a spreadsheet with four worksheets; added a conditional style in the 2nd sheet; and set the first sheet as the active sheet. I've tested this for both the master branch and the 1.22.0 release, against PHP versions 7.4.26, PHP 8.0.13 and PHP 8.1.0 and it works as expected for I've repeated that exercise with a new spreadsheet with four worksheets, with the CF on the 3rd sheet, and the 2nd worksheet as the active sheet; again, this works as expected for Xlsx and Xls and Ods. |
Hi, thank you for a quick reply. I've tested versions from 1.15 to 1.22. Here's a full, minimal, reproducible example: https://drive.google.com/file/d/1matrA-VjujGJ_MUBwrxleTmBaT4JIcJR/view?usp=sharing Just run 'composer install' an then 'php reproduction.php' |
Interesting. However, it gets more interesting in the case of your file (from Google Sheets), where the It should be easy enough for me to provide a default to the first worksheet in that circumstance. |
Thanks, @MarkBaker for the blazing-fast reaction. You are the star in a team of superstars. |
Thank you for a quick turnaround! Can't wait for the next release with the fix :) |
Uh oh!
There was an error while loading. Please reload this page.
This is:
What is the expected behavior?
According to the documentation
Worksheet::getActiveSheet()
should always return "the one that will be active when the workbook is opened in MS Excel (or other appropriate Spreadsheet program)."What is the current behavior?
Currenty, the last Sheet is always marked as the Active Sheet after the file was loaded:
Worksheet:676
iterates over the file's SheetsWorksheet:713
loads conditional styles for the currently processed SheetConditionalStyles:36
delegates the loading to thesetConditionalStyles
methodConditionalStyles:174
callsWorksheet::getStyle
methodWorksheet:1422
callssetActiveSheetIndex
methodAssuming that all the Sheets are always loaded and that they are loaded in the order of the file's Sheets, the last Sheet in the file will always be set as the Active Sheet.
This functionality was working correctly in version 1.7.0 which I'm moving from. I've tried to downgrade to 1.15.0 but the issue is also there, so it's been in the code for quite some time. Versions below 1.15.0 are not compatible with PHP 8.0 so I can't go lower. This is a major blocker for me.
The root cause for me is that get
getStyle
method changes the Active Sheet Index. Generally methods that start with "get" shouldn't change the state of any objects.Proposed solutions:
getStyle
method to not change the data stateWhat are the steps to reproduce?
Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:
The text was updated successfully, but these errors were encountered: