Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Call to a member function getStringAtIndex() on null #726

Closed
sauem opened this issue Feb 21, 2020 · 4 comments · Fixed by #810
Closed

Call to a member function getStringAtIndex() on null #726

sauem opened this issue Feb 21, 2020 · 4 comments · Fixed by #810

Comments

@sauem
Copy link

sauem commented Feb 21, 2020

This my code ( like sample doc , the excel file had 200k rows )

 $fileName = Yii::getAlias("@backend/web/export/200.xlsx");
        $reader = ReaderFactory::createFromFile($fileName);
        $reader->open($fileName);

        foreach ($reader->getSheetIterator() as $sheet){
            if($sheet->getName() == "sheet1"){
                foreach ($sheet->getRowIterator() as $rows){
                    var_dump($rows);
                }
            }
        }
 $reader->close();

end error when print result


Call to a member function getStringAtIndex() on null

in /Applications/AMPPS/project/omega/vendor/box/spout/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php at line 237

how can fix it?

@madflow
Copy link
Contributor

madflow commented Mar 2, 2020

how can fix it?

Start by posting the file you are trying to read.

@NightIsland
Copy link

I'm having this error too, albeit from a very different implementation.

I've cut the file I'm trying to open down to two rows, grab it here: ae1x.xlsx.

Converting a CSV to XLSX in Numbers for macOS works fine, but this file was generated from the same CSV read into Microsoft Excel for Mac (latest version) and exported as strict XLSX. I'm having trouble reading this file in lots of PHP readers, so I suspect a greater problem.

The stack trace is:
PHP Fatal error: Uncaught Error: Call to a member function getStringAtIndex() on null in /Users/xxx/Desktop/test/spout/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php:241
Stack trace:
#0 /Users/xxx/Desktop/test/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php(152): Box\Spout\Reader\XLSX\Manager\SharedStringsManager->getStringAtIndex(0)
#1 /Users/xxx/Desktop/test/spout/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php(96): Box\Spout\Reader\XLSX\Helper\CellValueFormatter->formatSharedStringCellValue('0')
#2 /Users/xxx/Desktop/test/spout/src/Spout/Reader/XLSX/RowIterator.php(361): Box\Spout\Reader\XLSX\Helper\CellValueFormatter->extractAndFormatNodeValue(Object(DOMElement))
#3 /Users/xxx/Desktop/test/spout/src/Spout/Reader/XLSX/RowIterator.php(280): Box\Spout\Reader\XLSX\RowIterator->getCell(Object(DOMElement))
#4 [internal function]: Box\Spout\Reader\XLSX\RowIterator->processCellStartingNode(Object(Box\Spout\Reader\Wrapper\XMLReader))
#5 /Users/xxx/Desktop/test/spout/src/Spout/Reader/Common/XMLProcessor. in /Users/xxx/Desktop/test/spout/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php on line 241

@DrZell
Copy link

DrZell commented Feb 10, 2021

Same here but, when I open the xlsx with LibreOffice, save it with no changes, it works again.

@adrilo
Copy link
Collaborator

adrilo commented May 12, 2021

I just found out that there are 2 formats behind the XLSX format: transitional (widely used, supported by Spout) and strict (not supported). The file that was sent is using the strict format. This format uses different namespaces for their XML files and Spout was not able to parse them properly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants