-
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
XLSX reader - Exception : You must specify a worksheet or a scope for a Named Range #1686
Comments
I have this problem... Solutions?? Return to PHPExcel-1.8 ?
|
Is it possible you could tag this in a release so it fixes Laravel Excel package as they have explicitly included this package as |
If you feel comfortable go into NamedRange.php in the source code and comment lines 20,21,22 out. Save the file and this should then work. I was having the same issue some where its not setting $worksheet or $scope variables. There should be logic in this code file that doesn't default them to null but instead sets them to something else a default value. |
I have the same issue but only when filling the loadSheetsOnly array. Example: <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
$reader = IOFactory::createReaderForFile('example.xlsx');
$reader->setLoadSheetsOnly(['Sheet 1', 'Sheet 2']);
$spreadsheet = $reader->load('example.xlsx'); It throws the error: "PhpOffice\PhpSpreadsheet\Exception: You must specify a worksheet or a scope for a Named Range" due to loading only specific sheets. (Xlsx file contains 3 sheets ('Sheet 1', 'Sheet 2', 'Sheet 3'))
PhpSpreadsheet - 1.15.0 |
* Fix for 3 Issues Involving ReadXlsx and NamedRange Issues #1686 and #1723, which provide sample spreadsheets, are probably solved by this ticket. Issue #1730 is also probably solved, but I have no way to verify. There are two problems with how PhpSpreadsheet is handling things now. Although the first problem is much less severe, and isn't really a factor in the issues named above, it is helpful to get it out of the way first. If you define a named range in Excel, and then delete the sheet where the range exists, Excel saves the range as #REF!. If there is a cell which references the range, it will similarly have the value #REF! when you open the Excel file. Currently, PhpSpreadsheet discards the #REF! definition, so a cell which references the range will appear as #NAME? rather than #REF!. This PR changes the behavior so that PhpSpreadsheet retains the #REF! definition, and cells which reference it will appear as #REF!. The second problem is the more severe, and is, I believe, responsible for the 3 issues identified above. If you define a named range and the sheet on which the range is defined does not exist at the time, Excel will save the range as something like: '[1]Unknown Sheet'!$A$1 If a cell references such a range, Excel will again display #REF!. PhpSpreadsheet currently throws an Exception when it encounters such a definition while reading the file. This PR changes the behavior so that PhpSpreadsheet saves the definition as #REF!, and cells which reference it will behave similarly. For the record, I will note that Excel does not magically recalculate when a missing sheet is subsequently added, despite the fact that the reference might now become resolvable. PhpSpreadsheet behaves likewise. * Remove Dead Code in Test Identified it after push but before merge.
Hi Alex,
Ah, that's what I'm trying to do only load certain spreadsheets. I Found commenting those lines out in NamedRange.php did it and it's not effected the running of the code. It's probably not passing down the worksheet for some reason to that bit of code. Definitely sounds like a bug to me.
Kevin
…________________________________
From: alexxxxkkkk <[email protected]>
Sent: 10 December 2020 17:01
To: PHPOffice/PhpSpreadsheet <[email protected]>
Cc: kevsharp81 <[email protected]>; Comment <[email protected]>
Subject: Re: [PHPOffice/PhpSpreadsheet] XLSX reader - Exception : You must specify a worksheet or a scope for a Named Range (#1686)
I have the same issue but only when filling the loadSheetsOnly array.
Example:
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
$reader = IOFactory::createReaderForFile('example.xlsx');
$reader->setLoadSheetsOnly(['Sheet 1', 'Sheet 2']);
$spreadsheet = $reader->load('example.xlsx');
It throws the error: "PhpOffice\PhpSpreadsheet\Exception: You must specify a worksheet or a scope for a Named Range" due to loading only specific sheets. (Xlsx file contains 3 sheets ('Sheet 1', 'Sheet 2', 'Sheet 3'))
PhpOffice\PhpSpreadsheet\Exception: You must specify a worksheet or a scope for a Named Range
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/NamedRange.php:21
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/DefinedName.php:97
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php:1399
PhpSpreadsheet - 1.15.0
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#1686 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABVHMDDJK5P7UMLO7MY5GQDSUD5IHANCNFSM4S2EGSAQ>.
[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png]<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virus-free. www.avg.com<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
|
This is a bug report
What is the expected behavior?
Read a simple XLSX file (no formula inside) without exception
What is the current behavior?
The XLSX reader crashes with the message
What are the steps to reproduce?
test.zip
The above zip file contains the XLS and XLSX files that exhibit the behaviour. The XLS file is simply the XLSX file saved as XLS (no change in the spreadsheet itself).
Which versions of PhpSpreadsheet and PHP are affected?
Package 1.15.0
PHP 7.4
The text was updated successfully, but these errors were encountered: