2014-03-25 43 views
0

我使用PHPExcel來讀取3個文件。其中2個是xls,1個是xlsx。我爲任務創建了2個閱讀器,但遇到錯誤。PHPExcel在同一個網頁中不能有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,則會報錯。

請幫忙。

回答

0

你不能,如果你使用相同的變量每個讀者例如:你需要使用一個單獨的閱讀器的實例爲每個實例化的讀者:

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

謝謝!我認爲我只需要實例化一個閱讀器並將它用於每個文件。 –

相關問題