我正在尝试阅读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
。