使用PHPExcel从excel中获取值的范围


getting range of values from excel with PHPExcel

我正在尝试从Excel中读取一系列值。这是我使用的代码。

//  Include PHPExcel_IOFactory
include 'Classes/PHPExcel/IOFactory.php';
$inputFileName = 'test.xlsx';
//  Read your Excel workbook
try {
    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}

$cellValue = $objPHPExcel->getActiveSheet()->getCell('A1')->getValue();
echo "A1 is: ".$cellValue."<br>";

$dataArray = $objPHPExcel->getActiveSheet()
->rangeToArray(
        'A1:C1',     // The worksheet range that we want to retrieve
        NULL,        // Value that should be returned for empty cells
        TRUE,        // Should formulas be calculated (the equivalent of getCalculatedValue() for each cell)
        TRUE,        // Should values be formatted (the equivalent of getFormattedValue() for each cell)
        TRUE         // Should the array be indexed by cell row and cell column
        );
echo "number of items in array: ".count($dataArray);

由于某种原因,$dataArray的计数只有1,尽管我检索的范围应该匹配3个项目。可能是什么问题?

哦,这是一个数组。二维数组。2d数组中的每个数组表示一行。如果查询是A1:C3,那么它将返回3个主数组。