无法读取和操作Excel数据

时间:2015-05-31 22:35:24

标签: php import-from-excel

我正在尝试阅读excel.xlsx文件。但我不能,我正在阅读一个名为PHPExcel的API,但我不能让它工作。这就是我试过的:

<?php
    // get access to the class
    require_once 'Classes/PHPExcel.php';
    include 'Classes/IOFactory.php';

    $inputFileName = 'teste.xlsx';

    //  Read your 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());
    }

    //  Get worksheet dimensions
    $sheet = $objPHPExcel->getSheet(0); 
    $highestRow = $sheet->getHighestRow(); 
    $highestColumn = $sheet->getHighestColumn();

    //  Loop through each row of the worksheet in turn
    for ($row = 1; $row <= $highestRow; $row++){ 
        //  Read a row of data into an array
        $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,NULL, TRUE, FALSE);  

       echo $rowData[$row];
    }

?>  

在for循环结束时,我尝试阅读或echo数据,但我收到的错误如:Undefined offset

0 个答案:

没有答案