<html>
<head>
<title> 浏览Excel表格中的数据</title>
<head>
<center>
<?php
error_reporting(E_ALL);
date_default_timezone_set('Asia/ShangHai');
include_once('Classes/PHPExcel/IOFactory.php');//包含类文件
$filename = "C:/Users/joey/Desktop/test.xlsx";//要读取的excel文件
if (!file_exists($filename)) {
exit("not found.\n");
}
$reader = PHPExcel_IOFactory::createReader('Excel2007'); //设置以Excel5格式(Excel97-2003工作簿)
$PHPExcel = $reader->load($filename); // 载入excel文件
$sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumm = $sheet->getHighestColumn(); // 取得总列数
/** 循环读取每个单元格的数据 */
$dataset=array();
echo "<table border=1>";
//for ($row = 1; $row <= $highestRow; $row++){//行数是以第1行开始
//for ($column = 'A'; $column <= $highestColumm; $column++) {//列数是以A列开始
for ($column = 'A'; $column <= $highestColumm; $column++){//行数是以第1行开始
for ($row =1; $row <= $highestRow; $row++) {//列数是以A列开始
//$dataset[$row][] = $sheet->getCell($column.$row)->getValue();
echo "<tr>";
echo "<td>".$sheet->getCell($column.$row)->getValue()."</td>";
echo "</tr>";
}
}
echo "</table>";
?>
</center>
</body>
</html>
PHPExcel最新版下载:
http://phpexcel.codeplex.com/