Skip to content

Undefined index $ : while importing excel file #687

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

Closed
sidrafarooq opened this issue Sep 26, 2018 · 13 comments
Closed

Undefined index $ : while importing excel file #687

sidrafarooq opened this issue Sep 26, 2018 · 13 comments

Comments

@sidrafarooq
Copy link

sidrafarooq commented Sep 26, 2018

This is:

-  a bug report

What is the expected behavior?

Trying to import an excel file (.xlsx) and file should be imported without any error

What is the current behavior?

During import i am getting undefined index $ error (IOFactory::load method is throwing this error) when i searched it, its because of autoFilter being applied.

2018-09-26 07:05:22 : #0 /var/www/html/project/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(291): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/var/www/html/s...', 291, Array)
#1 /var/www/html/project/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(207): PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString('$A')
#2 /var/www/html/project/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/AutoFilter.php(111): PhpOffice\PhpSpreadsheet\Cell\Coordinate::rangeBoundaries('$A$1:$K$1')
#3 /var/www/html/project/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php(1076): PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter->setRange('$A$1:$K$1')
#4 /var/www/html/project/app/Excel/FileLoader.php(286): PhpOffice\PhpSpreadsheet\Reader\Xlsx->load('/var/www/html/s...')

What are the steps to reproduce?

just upload an excel file downloaded through phpspreadsheet all filters applied (autoFilter are like this $A$1:$K$1 the dollar sign is creating problem when used in Coordinate.php line 291)

<?php

require __DIR__ . '/vendor/autoload.php';

$reader = IOFactory::createReaderForFile($file_name);
$excel    =   $reader->load($file_name);

Which versions of PhpSpreadsheet and PHP are affected?

Latest
1.4.0

@PowerKiKi
Copy link
Member

Can be easily reproduced with:

<?php
require 'vendor/autoload.php';

var_dump(\PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString('$A'));

PR welcome to fix it

@sidrafarooq
Copy link
Author

sidrafarooq commented Oct 7, 2018

@PowerKiKi i fixed it by removing "$" sign.

$autoFilterRange = str_replace("$", "", $autoFilterRange);

at line: /var/www/html/project/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php(1076): PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter->setRange('$A$1:$K$1')

so the values passed within setRange is "A1:K1"

and as we cant change the library directly so we added patch so that changes can persist themselves whenever we ran composer install or update.

For now library is working okay.

@yudina-m
Copy link

I created PR with suggested change and also added an Exception to Coordinate::columnIndexFromString, similar to the symbol limit. Unit tests are updated as well.

@stale
Copy link

stale bot commented Dec 12, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Dec 12, 2018
@stale stale bot closed this as completed Dec 19, 2018
@danaki
Copy link

danaki commented Mar 20, 2019

This issue is not fixed but closed. If a sheet contains autofilter it produces an error similar to undefined index $ error while loading spreedsheet file. Please reopen the issue.

@beraldo
Copy link

beraldo commented Jun 1, 2019

I am facing the same issue :(

@sidrafarooq
Copy link
Author

I am facing the same issue :(

i added above the way how to fix it and it is working all fine..

@beraldo
Copy link

beraldo commented Jun 1, 2019

@yalwayzm33 yes, I saw. Thank you, by the way.

But it's a bug and it would be great if the project was updated. Changing the source of third party software is not a good idea, but I'll do it until there is an update

@sidrafarooq
Copy link
Author

@yalwayzm33 yes, I saw. Thank you, by the way.

But it's a bug and it would be great if the project was updated. Changing the source of third party software is not a good idea, but I'll do it until there is an update

i know that thats why i added a patch it

"and as we cant change the library directly so we added patch so that changes can persist themselves whenever we ran composer install or update."

@PowerKiKi
Copy link
Member

See the comments in #718 to create a PR that could be merged to fix this

@gdianov
Copy link

gdianov commented Aug 22, 2019

I had the same problem, but the error itself appeared in the Excel file itself, the format of the cell in which the text was located was like Number and this is not correct. Redid the cell format on Text and it worked. Check cell format.

@AlexeyKosov
Copy link

If this repository is abandoned and there's no maintainers who can solve such critical issues, please let users know about that (so that the package is highlighted with yellow in composer) rather than just keeping bug reports closed.

@astronati
Copy link
Contributor

@PowerKiKi #1326 is the PR but none is reviewing it. Could you help us please?

PowerKiKi pushed a commit to astronati/PhpSpreadsheet that referenced this issue Mar 2, 2020
The `setRange` method of the `Xlsx/AutoFilter` class expects a filter
range format like "A1:E10". The returned value from
`$this->worksheetXml->autoFilter['ref']` could contain "$" and returning
a value like "$A$1:$E$10".

Fixes PHPOffice#687
Fixes PHPOffice#1325
Closes PHPOffice#1326
PowerKiKi pushed a commit that referenced this issue Mar 2, 2020
The `setRange` method of the `Xlsx/AutoFilter` class expects a filter
range format like "A1:E10". The returned value from
`$this->worksheetXml->autoFilter['ref']` could contain "$" and returning
a value like "$A$1:$E$10".

Fixes #687
Fixes #1325
Closes #1326
paulkned pushed a commit to paulkned/PhpSpreadsheet that referenced this issue Mar 6, 2020
The `setRange` method of the `Xlsx/AutoFilter` class expects a filter
range format like "A1:E10". The returned value from
`$this->worksheetXml->autoFilter['ref']` could contain "$" and returning
a value like "$A$1:$E$10".

Fixes PHPOffice#687
Fixes PHPOffice#1325
Closes PHPOffice#1326
@oleibman oleibman removed the stale label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

10 participants