Php 无法读取和操作excel数据
我正在尝试读取一个Php 无法读取和操作excel数据,php,import-from-excel,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
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];
}
?>
是否返回每个连续行的单元格数据数组?如果是这样,并且您希望从每一行读取单元格,那么您可能希望使用不同的索引来循环遍历每一行。