2016-09-27 23 views
0

爲了維護一些陳舊的垃圾代碼,我在導入symfony命令時遇到了phpexcel的問題。從phpexcel的其他表中讀取公式

似乎庫無法正確計算出與活動工作表相同文檔的另一頁鏈接的公式。

我得到的錯誤是:

[PHPExcel_Calculation_Exception] 
Price Template Map!B2 -> Invalid cell coordinate A 

我的代碼是:

try { 
    $inputFileType = \PHPExcel_IOFactory::identify($filePath); 
    $objReader = \PHPExcel_IOFactory::createReader($inputFileType); 
    $objReader->setLoadSheetsOnly(array($this->getListName(), 'Template Info')); 
    $objReader->setIncludeCharts(true); 

    $objPHPExcel = $objReader->load($filePath); 
} catch (\Exception $e) { 
    throw new \Exception("Invalid file"); 
} 
$sheet = $objPHPExcel->getActiveSheet(); 
$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestColumn(); 

$fieldsNumber = array(); 
$filterData = array(); 
$templateIdList = array(); 

for ($i = 1; $i <= $highestRow; $i++) { 
    $rowData = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, null, true, false); 
    $rowData = $rowData[0]; 
    var_dump($rowData); 
} 

第一行與頭被正確讀取,但其餘的不是。

我的公式是:

=VLOOKUP(A18,'Template Info'!A:C,3,FALSE)"

不要猶豫,問我更多的信息,如果你需要它!

謝謝大家提前:)!

回答

2

問題是列引用:所述PHPExcel計算引擎支持範圍的引用(甚至到其他工作表),而不是行或列引用

所以

=VLOOKUP(A18,'Template Info'!A1:C100,3,FALSE) 

將是有效的,但

=VLOOKUP(A18,'Template Info'!A:C,3,FALSE) 

無法計算

0

使用getCalculatedValue()函數。

+0

問題是rangeToArr第三個參數是一個布爾值,用於知道庫是否應該使用getCalculatedValue()或不使用getCalculatedValue()。它目前設置爲true。如果我將它設置爲false,我將以原始格式接收公式。 – Kern

+0

爲什麼不設置爲true? –

+0

它被設置爲true :) – Kern