Question

I'm using PHPExcel to read 3 files. 2 of them are xls and 1 of the is xlsx. I create 2 reader for the task but encountered error.

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

Here is my code

$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");

The $inputFileType is variable for the type of uploaded file(which is xlsx.). The code works fine if I upload xls. but give error if the uploaded file is xlsx.

Please help.

Was it helpful?

Solution

You can't if you use the same variable for each reader instance: you need to use a separate reader instance for each reader that you instantiate:

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

or (at least) instantiate a new reader for each file as you load it

$objReader = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcelShip = $objReader->load("Ship to mapping.xls");
$objReader = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcelMat = $objReader->load("Material Mapping.xls");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top