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

Reading a sheet protected Excel file (saved in Mac OS) is not working #3423

Open
chiborg opened this issue Mar 1, 2023 · 5 comments
Open

Comments

@chiborg
Copy link

chiborg commented Mar 1, 2023

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the current behavior?

This code is not working when opens an XLS type file:
$objPHPExcel = IOFactory::load($file->getRealPath());
The error message is:
Unexpected file pass record length

This code is not working when opens an XLSX type file:
$string = $objPHPExcel->getActiveSheet()->getCell('A1')->getValue()
The error message is:
Your requested sheet index: -1 is out of bounds. The actual number of sheets is 0.

What are the steps to reproduce?

The files was created by Excel for Mac.
There only one sheet, what have write protected cells with password.

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

XLS
XLSX

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet version: 1.28.0
php version: 8.1.3

@MarkBaker
Copy link
Member

Are these protected spreadsheet files? Or are they encrypted? PhpSpreadsheet can't read encrypted files.

Otherwise I'd need to look at the actual files themselves to see exactly what the problem was

@chiborg
Copy link
Author

chiborg commented Mar 1, 2023

Protected, not encrypted.
The problem is only with Excel for Mac.
When I load a file, what save on Windows or Linux Libreoffice, every codes are working.

@MarkBaker
Copy link
Member

So another odd difference between Windows Excel and Mac Excel.

Is it possible to attach example files?

@vladojovanovski
Copy link


EDAS-ART IMAGINATION-2023-200.xlsx
example attached

@oleibman
Copy link
Collaborator

oleibman commented Sep 8, 2023

Thank you for uploading the file. PhpSpreadsheet does have a problem with it, but I think it is unrelated to this issue. I will open a new one for it.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Sep 10, 2023
Fix PHPOffice#3720. Third-party product created a spreadsheet which PhpSpreadsheet could not read because of unexpected namespacing in workbook.xml.rels.

The file which demonstrated the problem was attached to PHPOffice#3423, however I do not believe it was related to the original problem. Nevertheless, the original issue specifically called out Protection, so I put some Protection tests in the validation test for the fix. In doing so, I found that Style/Protection is particularly confusing. Its properties will often have the value `inherit`, which isn't all that helpful; and, even when the `locked` value is `protected`, the cell won't actually be locked unless the sheet is protected as well. The `hidden` property is even more obscure - it applies only to formulas, and refers to hiding the property on the formula bar, not in the cell. I have added methods `isLocked` and `isHiddenOnFormulaBar` to `Cell`. I corrected the docs to explain this. And, as long as I was looking at the docs, I corrected some examples to use `getHighestDataRow/Column` rather than `getHighestRow/Column`, a frequent problem for users (e.g. PHPOffice#3721).

As a side note, the change to Cell.php is my first use of the nullsafe operator. This is one of many new options available now that we require Php8.0+.
oleibman added a commit that referenced this issue Sep 13, 2023
* Unexpected Namespacing in rels File

Fix #3720. Third-party product created a spreadsheet which PhpSpreadsheet could not read because of unexpected namespacing in workbook.xml.rels.

The file which demonstrated the problem was attached to #3423, however I do not believe it was related to the original problem. Nevertheless, the original issue specifically called out Protection, so I put some Protection tests in the validation test for the fix. In doing so, I found that Style/Protection is particularly confusing. Its properties will often have the value `inherit`, which isn't all that helpful; and, even when the `locked` value is `protected`, the cell won't actually be locked unless the sheet is protected as well. The `hidden` property is even more obscure - it applies only to formulas, and refers to hiding the property on the formula bar, not in the cell. I have added methods `isLocked` and `isHiddenOnFormulaBar` to `Cell`. I corrected the docs to explain this. And, as long as I was looking at the docs, I corrected some examples to use `getHighestDataRow/Column` rather than `getHighestRow/Column`, a frequent problem for users (e.g. #3721).

As a side note, the change to Cell.php is my first use of the nullsafe operator. This is one of many new options available now that we require Php8.0+.

* Minor Simplifications

* Scrutinizer

It's being silly again. In many tests, we test a variable for non-null, then use that variable later and Scrutinizer knows it's not null. Not here. Oh well.

* Add Methods

Test if protected without allocating cell if it doesn't exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants