thinkphp3.2 phpexcel在linux系統報錯
阿新 • • 發佈:2019-01-29
最近有個tp3.2的專案遷移到linux系統上了,突然有天發現原本在win server 2008上執行沒問題的excel匯出功能在新的系統上不能使用了。報錯如下:
說是1762行有問題,找到這個檔案的程式碼看看:
/**
* Get an instance of this class
*
* @access public
* @param PHPExcel $workbook Injected workbook for working with a PHPExcel object,
* or NULL to create a standalone claculation engine
* @return PHPExcel_Calculation
*/
public static function getInstance(PHPExcel $workbook = NULL) {
if ($workbook !== NULL) {
if (isset(self::$_workbookSets[$workbook->getID()])) {
return self::$_workbookSets[$workbook->getID()];
}
return new PHPExcel_Calculation($workbook);
}
if (!isset(self::$_instance) || (self::$_instance === NULL)) {
self::$_instance = new PHPExcel_Calculation();
}
return self::$_instance;
} // function getInstance()
這個函式getInstance(PHPExcel $workbook = NULL)
發現這個函式 定義的時候多了個PHPExcel
這次是1721行,然後再次找到這個位置的檔案刪除 PHPExcel這個東東,然後繼續上傳,測試,後面大多數錯誤都是這種,刪掉函式定義時的PHPExcel即可,但是錯誤一個接一個,這是需要替換的檔案:
這個地方要加個空格,這樣才不會替換錯誤,好了,繼續上傳測試.
然後就這樣了…..當時內心是崩潰的…
繼續找問題吧,在測試php檔案裡面輸出變數進行測試。
PHPExcel\PHPExcel\Calculation\Functions.php 下面這個檔案,中有個 **TYPE**函式,將其中的break去掉,上傳,ok了
/**
* TYPE
*
* Returns a number that identifies the type of a value
*
* @param value The value you want tested
* @return number N converts values listed in the following table
* If value is or refers to N returns
* A number 1
* Text 2
* Logical Value 4
* An error value 16
* Array or Matrix 64
*/
public static function TYPE($value = NULL) {
$value = self::flattenArrayIndexed($value);
if (is_array($value) && (count($value) > 1)) {
$a = array_keys($value);
$a = array_pop($a);
// Range of cells is an error
if (self::isCellValue($a)) {
return 16;
// Test for Matrix
} elseif (self::isMatrixValue($a)) {
return 64;
}
} elseif(empty($value)) {
// Empty Cell
return 1;
}
$value = self::flattenSingleValue($value);
if (($value === NULL) || (is_float($value)) || (is_int($value))) {
return 1;
} elseif(is_bool($value)) {
return 4;
} elseif(is_array($value)) {
return 64;
break;
} elseif(is_string($value)) {
// Errors
if ((strlen($value) > 0) && ($value{0} == '#')) {
return 16;
}
return 2;
}
return 0;
} // function TYPE()
這是完整流程,線上系統用的是centos7,php是也是7。這個估計是不相容造成的,也沒有再深一步研究了,畢竟其實有新的excel外掛了,要不是,有太多程式碼需要修改,估計我直接換外掛了。