PHPExcel不能在同一个网页上有2个阅读器


PHPExcel can't have 2 reader in the same web page?

我使用PHPExcel读取3个文件。其中2个是XLS, 1个是xlsx。我为任务创建了2个阅读器,但遇到了错误。

HTTP Error 500.0 - Internal Server Error
C:'AppServ'php5'php-cgi.exe - The FastCGI process exited unexpectedly

我的代码

$inputFileType = PHPExcel_IOFactory::identify($conPath);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($conPath);
$objReader = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcelShip = $objReader->load("Ship to mapping.xls");
$objPHPExcelMat = $objReader->load("Material Mapping.xls");

$inputFileType是变量,表示上传的文件类型(xlsx.)。如果我上传xls,代码可以正常工作。但如果上传的文件是xlsx,则给出错误。

请帮。

如果您为每个阅读器实例使用相同的变量,则不能:您需要为每个实例化的阅读器使用单独的阅读器实例:

$objReader1 = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcelShip = $objReader1->load("Ship to mapping.xls");
$objReader2 = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcelMat = $objReader2->load("Material Mapping.xls");

或者(至少)在加载文件时为每个文件实例化一个新的读取器

$objReader = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcelShip = $objReader->load("Ship to mapping.xls");
$objReader = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcelMat = $objReader->load("Material Mapping.xls");