require("../PHPExcel/PHPExcel/IOFactory.php");
② 加载要进行读取的文件
$phpexcel = PHPExcel_IOFactory::load("./demo.xlsx");
③ 通过内部迭代器的方法获取sheet个数
foreach($phpexcel->getWorksheetIterator() as $sheet) {}
④ 通过迭代器逐行读取
foreach ($sheet->getRowIterator() as $row) {}
⑤ 通过迭代器逐列读取
foreach ($row->getCellIterator() as $cell) {}
⑥ 再通过获得的行和列数据获得里面的内容
$data = $cell->getValue();
总结步骤:
引入类文件--->引入读取的文件--->读取sheet数->逐行读取->逐列读取->读取行和列的值
<?php //引入读取excel的类文件 require("../PHPExcel/PHPExcel/IOFactory.php"); //加载文件 $phpexcel = PHPExcel_IOFactory::load("./demo.xlsx"); //循环读取sheet foreach($phpexcel->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 />"; } echo "<br />"; } ?>
原文:http://www.cnblogs.com/3-tu/p/6336927.html