标签:
需要用到PHPExcel这个类
附上代码
1 <?php 2 require_once ‘inc/PHPExcel.php‘; 3 require_once ‘inc/PHPExcel/IOFactory.php‘; 4 require_once ‘inc/PHPExcel/Reader/Excel2007.php‘; 5 require_once ‘inc/PHPExcel/Reader/Excel5.php‘; 6 7 //判断excel版本 8 $objReader = PHPExcel_IOFactory::createReader(‘Excel2007‘); 9 if (!$objReader->canRead($filepath)){ 10 $objReader = PHPExcel_IOFactory::createReader(‘Excel5‘); 11 if (!$objReader->canRead($filepath)){ 12 exit(‘请使用03/07版本excel‘); 13 } 14 } 15 16 $objPHPExcel = $objReader->load($filepath); //$filepath为Excel 路径 17 $objWorksheet = $objPHPExcel->getActiveSheet(); 18 $excelRows = $objWorksheet->getHighestRow(); // 取得总行数 19 $highestColumn = $objWorksheet->getHighestColumn(); 20 $excelCols = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数 21 22 for ($i = 2; $i <= $excelRows; $i++){ 23 //注意,第一列是从0开始的 24 $first= $objWorksheet->getCellByColumnAndRow(0, $i)->getValue(); 25 $second = $objWorksheet->getCellByColumnAndRow(1, $i)->getValue(); 26 $third = $objWorksheet->getCellByColumnAndRow(2, $i)->getValue(); 27 $four = $objWorksheet->getCellByColumnAndRow(3, $i)->getValue(); 28 $five = $objWorksheet->getCellByColumnAndRow(4, $i)->getValue(); 29 $six = $objWorksheet->getCellByColumnAndRow(5, $i)->getValue(); 30 $seven = $objWorksheet->getCellByColumnAndRow(6, $i)->getValue(); 31 32 //获取到每个值后就可以对数据进行处理了 33 } 34 35 ?>
下载地址:http://pan.baidu.com/s/1i35ppBJ
完整版是api,另外一个是程序中用的。
标签:
原文地址:http://www.cnblogs.com/blueskycc/p/4348428.html