PHPExcel 无法加载带有公式的电子表格
PHPExcel cannot load spreadsheet with formula
尝试为文件创建 reader 时,出现一些奇怪的错误。我使用的是 dev-master 分支,然后切换到 1.8.1,但这似乎没有任何区别,因此我认为问题出在电子表格上。
电子表格中使用了相当多的公式,例如:
=IFERROR(VLOOKUP($A*1,'List'!A:H,P5,FALSE),"")
=IF(A15>0,1,"")
=IFERROR(VLOOKUP($A15,'Master'!$A:$R,18,FALSE)*P15,"")
=IF(A16=0,"",IFERROR(VLOOKUP($A16,'Master'!$A:$O,2,FALSE),"Not Available"))
PHP:
$objReader = \PHPExcel_IOFactory::createReaderForFile($filename);
$r = $objReader->load($filename);
错误:
PHP Notice: Undefined index: $ in
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php
on line 809 PHP Stack trace: PHP 1. {main}()
/var/www/html/myApp/app/console:0 PHP 2.
Symfony\Component\Console\Application->run()
/var/www/html/myApp/app/console:22 PHP 3.
Symfony\Bundle\FrameworkBundle\Console\Application->doRun()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
PHP 4. Symfony\Component\Console\Application->doRun()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
PHP 5. Symfony\Component\Console\Application->doRunCommand()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
PHP 6. Symfony\Component\Console\Command\Command->run()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:904
PHP 7. App\MyApp\ImportBundle\Command\ImportCommand->execute()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:244
PHP 8. App\MyApp\ImportBundle\ImportService->import()
/var/www/html/myApp/src/App/MyApp/ImportBundle/Command/ImportCommand.php:35
PHP 9. App\MyApp\ImportBundle\Other\Importer->import()
/var/www/html/myApp/src/App/MyApp/ImportBundle/ImportService.php:44 PHP
10. App\MyApp\ImportBundle\Other\Importer->createAllocation() /var/www/html/myApp/src/App/MyApp/ImportBundle/Other/Importer.php:43
PHP 11.
App\MyApp\ImportBundle\Other\AllocationImporter->import()
/var/www/html/myApp/src/App/MyApp/ImportBundle/Other/Importer.php:70
PHP 12.
App\MyApp\ImportBundle\AbstractSpreadsheetReader->loadSpreadsheet()
/var/www/html/myApp/src/App/MyApp/ImportBundle/Other/AllocationImporter.php:26
PHP 13. PHPExcel_Reader_Excel2007->load()
/var/www/html/myApp/src/App/MyApp/ImportBundle/AbstractSpreadsheetReader.php:31
PHP 14. PHPExcel_Worksheet_AutoFilter->setRange()
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php:1012
PHP 15. PHPExcel_Cell::rangeBoundaries()
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet/AutoFilter.php:131
PHP 16. PHPExcel_Cell::columnIndexFromString()
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php:729
一个问题是像
这样的公式
=IFERROR(VLOOKUP($A*1,'List'!A:H,P5,FALSE),"")
PHPExcel 不完全支持行或列引用,例如 'List'!A:H
或 'Master'!$A:$R
它确实支持范围引用,所以 'List'!A1:H1000
或 'Master'!$A1:$R1024
是有效的
编辑
但是,从堆栈转储来看,它看起来像是自动过滤器中的问题
作为 "Quick and Dirty" hack,您可以检查文件 Classes/PHPExcel/Cell.php
并在 rangeBoundaries()
方法中,在第 715 行或附近(具体取决于 release/build 您're 运行), 寻找
// Uppercase coordinate
$pRange = strtoupper($pRange);
并尝试将其更改为:
// Uppercase coordinate
$pRange = strtoupper(str_replace('$', '', $pRange));
尝试为文件创建 reader 时,出现一些奇怪的错误。我使用的是 dev-master 分支,然后切换到 1.8.1,但这似乎没有任何区别,因此我认为问题出在电子表格上。
电子表格中使用了相当多的公式,例如:
=IFERROR(VLOOKUP($A*1,'List'!A:H,P5,FALSE),"")
=IF(A15>0,1,"")
=IFERROR(VLOOKUP($A15,'Master'!$A:$R,18,FALSE)*P15,"")
=IF(A16=0,"",IFERROR(VLOOKUP($A16,'Master'!$A:$O,2,FALSE),"Not Available"))
PHP:
$objReader = \PHPExcel_IOFactory::createReaderForFile($filename);
$r = $objReader->load($filename);
错误:
PHP Notice: Undefined index: $ in
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php
on line 809 PHP Stack trace: PHP 1. {main}()
/var/www/html/myApp/app/console:0 PHP 2.
Symfony\Component\Console\Application->run()
/var/www/html/myApp/app/console:22 PHP 3.
Symfony\Bundle\FrameworkBundle\Console\Application->doRun()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
PHP 4. Symfony\Component\Console\Application->doRun()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
PHP 5. Symfony\Component\Console\Application->doRunCommand()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
PHP 6. Symfony\Component\Console\Command\Command->run()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:904
PHP 7. App\MyApp\ImportBundle\Command\ImportCommand->execute()
/var/www/html/myApp/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:244
PHP 8. App\MyApp\ImportBundle\ImportService->import()
/var/www/html/myApp/src/App/MyApp/ImportBundle/Command/ImportCommand.php:35
PHP 9. App\MyApp\ImportBundle\Other\Importer->import()
/var/www/html/myApp/src/App/MyApp/ImportBundle/ImportService.php:44 PHP
10. App\MyApp\ImportBundle\Other\Importer->createAllocation() /var/www/html/myApp/src/App/MyApp/ImportBundle/Other/Importer.php:43
PHP 11.
App\MyApp\ImportBundle\Other\AllocationImporter->import()
/var/www/html/myApp/src/App/MyApp/ImportBundle/Other/Importer.php:70
PHP 12.
App\MyApp\ImportBundle\AbstractSpreadsheetReader->loadSpreadsheet()
/var/www/html/myApp/src/App/MyApp/ImportBundle/Other/AllocationImporter.php:26
PHP 13. PHPExcel_Reader_Excel2007->load()
/var/www/html/myApp/src/App/MyApp/ImportBundle/AbstractSpreadsheetReader.php:31
PHP 14. PHPExcel_Worksheet_AutoFilter->setRange()
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php:1012
PHP 15. PHPExcel_Cell::rangeBoundaries()
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet/AutoFilter.php:131
PHP 16. PHPExcel_Cell::columnIndexFromString()
/var/www/html/myApp/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php:729
一个问题是像
这样的公式=IFERROR(VLOOKUP($A*1,'List'!A:H,P5,FALSE),"")
PHPExcel 不完全支持行或列引用,例如 'List'!A:H
或 'Master'!$A:$R
它确实支持范围引用,所以 'List'!A1:H1000
或 'Master'!$A1:$R1024
是有效的
编辑
但是,从堆栈转储来看,它看起来像是自动过滤器中的问题
作为 "Quick and Dirty" hack,您可以检查文件 Classes/PHPExcel/Cell.php
并在 rangeBoundaries()
方法中,在第 715 行或附近(具体取决于 release/build 您're 运行), 寻找
// Uppercase coordinate
$pRange = strtoupper($pRange);
并尝试将其更改为:
// Uppercase coordinate
$pRange = strtoupper(str_replace('$', '', $pRange));