-
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
Data validation not working when opening & saving a file #1432
Comments
No suggestions, anybody? |
1.12.0 still doesn't work |
Try to open-and-save without doing anything at all in between. Then unzip both xlsx files and compare the content of each files. Can you pinpoint what changed? Second question, are you able to create a file from scratch, create the validation and save to for properly? |
Look at this line,
it is expected from the so I've solved the problem by adding this code just before the line mentioned
which checks for other possible validations to exist and if so, it creates the I think this is just a workaround that works for my current project, so I'll not suggest this as a patch. |
Thank you man! I put your changes in a "patches" folder, overriding through composer the default class autoload behavior for this specific class. It works like a charm. I also fixed the composer dependency to the current version, to avoid breaking changes. I hope it could be fixed in the near future. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Hello, Thanks. |
Thank you @eugenio11! |
More precisely, what happens in my case is:
|
I'm also on the waitlist. Any update on that? |
Let's get this fixed, please! It's been a while! |
I do not understand enough about this problem to work on it. But perhaps I can make a suggestion that will resonate with someone. The code to read the data validations from the alternate location in Xlsx Reader was merged some time ago, and I believe it is working correctly. I think the problem is happening in Xlsx writer. Xlsx Reader can now read from:
That's how it reads the list from another sheet. But, from the same sheet, it reads:
That's how it reads the list from the same sheet. (Just for clarity's sake, no extLst, no ext, no namespaces, except for xr:uid, which appears to not be required.) I don't know if the reader can handle both formats on the same worksheet. At this point, I'll add that I haven't seen what happens when you have both types of list. I also don't know what happens when you combine the first format with other things that require extLst (e.g. conditional formatting). Nevertheless, the solution might be to have the writer generate the appropriate format for each data validation if you can figure out what the appropriate format should be in each case. |
I have tried changing Xlsx writer to use extLst in this case. Excel complains "Replaced Part: /xl/worksheets/sheet1.xml part with XML error. Load error. Line 2, column 0." Nevertheless, that part loads successfully as Xml, and looks pretty much identical to the corresponding part in the input dataset. No idea how to proceed without better diagnostics from Excel. |
Aha! I found a helpful comment in // ConditionalFormattingRuleExtensionList
// (Must be inserted last. Not insert last, an Excel parse error will occur) I am as baffled by this requirement as the original author for Conditional Formatting must have been. But ... when I use extLst to write data validations after everything else, Excel does read it correctly. There are still lots of edge cases to worry about.
So, progress, but lots more work to go before slaying this one. |
It does look like "internal" data validations can be placed in extLst, so that makes things a little less complicated. |
See issues PHPOffice#1432 and PHPOffice#2149. Data validations on an Xlsx worksheet can be specified in two manners - one (henceforth "internal") if a list is specified from the same sheet, and a different one (henceforth "external") if a list is specified from a different sheet. Xlsx worksheet reader formerly processed only the internal format; PR PHPOffice#2150 fixed this so that both would be processed correctly on read. However, Xlsx worksheet writer outputs data validators only in the internal format, and that does not work for external data validations; it appears, however, that internal data validations can be specified in external format. This PR changes Xlsx worksheet writer to use only the external format. Somewhat surprisingly, this must come after most of the other XML tags that constitute a worksheet. It shares this characteristic (and XML tag) with conditional formatting. The new test case DataValidator2Test includes a worksheet which has both internal and external data validation, as well as conditional formatting. There is some additional namespacing work supporting Data Validations that needs to happen on Xlsx reader. Since that is substantially unchanged with this PR, that work will happen in a future namespacing phase, probably phase 2. However, there are some non-namespace-related changes to Xlsx reader in this PR: - Cell DataValidation adds support for a new property sqref, which is initialized through Xlsx reader using a setSqref method. If not initialized at write time, the code will work as it did before the introduction of this property. In particular, before this change, data validation applied to an entire column (as in the sample spreadsheet) would be applied only through the last populated row. In addition, this also allows a user to extend a Data Validation over a range of cells rather than just a single cell; the new method is added to the documentation. - The topLeft property had formerly been used only for worksheets which use "freeze panes". However, as luck would have it, the sample dataset provided to demonstrate the Data Validations problem uses topLeft without freeze panes, slightly affecting the view when the spreadsheet is initially opened; PhpSpreadsheet will now do so as well. It is worth noting issue PHPOffice#2262, which documents a problem with the hasValidValue method involving the calculation engine. That problem existed before this PR, and I do not yet have a handle on how it might be fixed.
See issues #1432 and #2149. Data validations on an Xlsx worksheet can be specified in two manners - one (henceforth "internal") if a list is specified from the same sheet, and a different one (henceforth "external") if a list is specified from a different sheet. Xlsx worksheet reader formerly processed only the internal format; PR #2150 fixed this so that both would be processed correctly on read. However, Xlsx worksheet writer outputs data validators only in the internal format, and that does not work for external data validations; it appears, however, that internal data validations can be specified in external format. This PR changes Xlsx worksheet writer to use only the external format. Somewhat surprisingly, this must come after most of the other XML tags that constitute a worksheet. It shares this characteristic (and XML tag) with conditional formatting. The new test case DataValidator2Test includes a worksheet which has both internal and external data validation, as well as conditional formatting. There is some additional namespacing work supporting Data Validations that needs to happen on Xlsx reader. Since that is substantially unchanged with this PR, that work will happen in a future namespacing phase, probably phase 2. However, there are some non-namespace-related changes to Xlsx reader in this PR: - Cell DataValidation adds support for a new property sqref, which is initialized through Xlsx reader using a setSqref method. If not initialized at write time, the code will work as it did before the introduction of this property. In particular, before this change, data validation applied to an entire column (as in the sample spreadsheet) would be applied only through the last populated row. In addition, this also allows a user to extend a Data Validation over a range of cells rather than just a single cell; the new method is added to the documentation. - The topLeft property had formerly been used only for worksheets which use "freeze panes". However, as luck would have it, the sample dataset provided to demonstrate the Data Validations problem uses topLeft without freeze panes, slightly affecting the view when the spreadsheet is initially opened; PhpSpreadsheet will now do so as well. It is worth noting issue #2262, which documents a problem with the hasValidValue method involving the calculation engine. That problem existed before this PR, and I do not yet have a handle on how it might be fixed.
Version 1.18 - Doesn't work. |
PR 2265 has been applied only in master, if you want to test with that. I am unsure of when the next official release will happen. |
Fixed in 1.19.0 |
Facing the Same issue with 1.19. Steps to recreate, Create a dummy excel with a data validation of type List, $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath); |
@DeekshaPrabhub96 I got it broken in ms office 2007 version, have you tried opening the file in newer versions? For example, you can open it in Google Docs, it worked for me. |
Yes Working Fine with Google Docs but same issue with latest version of MSExcel (16.54). |
This is:
What am I trying to accomplish?
I want to open an XLSX file that has some List Dropdown validation rules in it, write some data in it and save it.
What is the expected behavior?
When opening and saving an Excel file, it should retain all the data validation inside it.
What is the current behavior?
It loses all data validation fields ( dropdowns, explanations etc)
What are the steps to reproduce?
Open the bellow excel file with data validation -> save it -> it loses validation.
Sample XLSX file to help reproduce
sample.xlsx
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:
Which versions of PhpSpreadsheet and PHP are affected?
"phpoffice/phpspreadsheet": "^1.11"
PHP 7.3
The text was updated successfully, but these errors were encountered: