首先去下载PHPEXCEL 百度一下就能下到,然后把它放到WAMP下面的WWW文件夹下
PHP文件也放在下面 ,把EXCEL文件也放在下面,然后就可以了。
<!DOCTYPE HTML>
<!DOCTYPE html><html>
<head>
<title>excel read</title>
</head>
<body>
<?php
//$dir = dirname(__FILE__)
//require_once $dir.'\PHPExcel\Classes\PHPExcel\IOFactory.php';
//equire_once '../PHPExcel/Classes/PHPExcel/IOFactory.php';
include_once('PHPExcel/Classes/PHPExcel/IOFactory.php');
include_once('PHPExcel.php');
include_once('PHPExcel/Classes/PHPExcel/Reader/Excel5.php');
//$FileName = $dir.'\test.xls';
$FileName = 'Price list.xlsx';
//加载EXCEL文件
$objPHPExcelReader = PHPExcel_IOFactory::load($FileName);
//循环读取文件
foreach ($objPHPExcelReader->getWorksheetIterator() as $sheet)
{
foreach ($sheet -> getRowIterator() as $row) //逐行处理
{
if ($row -> getRowIndex()<2) //确定从哪一行开始读取
{
continue;
}
foreach ($row -> getCellIterator() as $cell) //逐列读取
{
$data = $cell->getValue();
echo " $data";
}
echo '<br/>';
}
}
?>
</body>
</html>