php
  • excel
  • phpexcel
  • 2017-09-27 107 views 1 likes 
    1

    我有一個讀取數字是正確的問題,因爲在Excel工作表中它只是一個數字,但第二個返回一個公式。我已經嘗試了幾個關於論壇其他主題的方法,但都沒有正確的工作。我還能做些什麼來解決這個問題?我只需要從我的.xlsx excel文件中讀取幾個單元格。PHPExcel xlsx文件讀取器

    代碼:

    include "PHPExcel-1.8\Classes\PHPExcel\IOFactory.php"; 
    $inputFileName = 'C:\Users\tfd054it0154\Desktop\dane na spotkanie.xlsx'; 
    $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); 
    
    // Read Excel workbook 
    try { 
        $inputFileType = PHPExcel_IOFactory::identify($inputFileName); 
        $objReader = PHPExcel_IOFactory::createReader($inputFileType); 
        $objPHPExcel = $objReader->load($inputFileName); 
    } catch(Exception $e) { 
        die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); 
    } 
    $value1 = $objPHPExcel->getActiveSheet()->getCell('B8')->getValue(); 
    echo $value1; 
    $value2 = $objPHPExcel->getActiveSheet()->getCell('C8')->getValue(); 
    echo $value2; 
    
    +0

    可能的複製描述(https://stackoverflow.com/questions/563670/reading-an-excel-file-in-php) –

    回答

    0

    如果單元格包含一個公式,則返回getValue()公式本身,getCalculatedValue()計算並返回該公式的結果。

    如[讀取在PHP Excel文件]的PHPExcel documentation

    +0

    是,我之前使用過這個,但是得到了一個錯誤或者錯誤的編號,現在不記得了,而且我也無法重現錯誤來顯示你。 –

    +0

    很好地解釋真正的問題有助於......但不知道錯誤是什麼,幾乎不可能提供幫助;並且不知道該公式中使用的公式和數據,那麼不可能得出爲什麼你得到一個錯誤的數字 –

    +0

    我設法重現錯誤 用「getValue()」正確讀取「30」數字, '和錯誤然後來自'getCalculatedValue()' Img:[link] https://imgur.com/a/uGHKY –

    相關問題