我正在尝试从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个项目的范围。可能是什么问题?
答案 0 :(得分:0)
哦,它是一个数组数组。一个2d数组。 2d数组中的每个数组代表一行。如果查询为A1:C3
,则返回3个主数组。