标签:
PHP读取excel文档
项目需要读取Excel的内容,从百度搜索了下,主要有两个选择,第一个是PHPExcelReader,另外一个是PHPExcel。
1,require_once ‘/libs/PHPExcel-1.8.0/Classes/PHPExcel.php‘; //修改为自己的目录 2,echo ‘<p>TEST PHPExcel 1.8.0: read xlsx file</p>‘; 3,$objReader=PHPExcel_IOFactory::createReaderForFile($filename); 4,$objPHPExcel = $objReader->load($filename); 5,$objPHPExcel->setActiveSheetIndex(1); 6,$date = $objPHPExcel->getActiveSheet()->getCell(‘A16‘)->getValue();
1 <table id="table_id"> 2 <?php 3 $objWorksheet = $objPHPExcel->getActiveSheet(); 4 $i = 0; 5 foreach($objWorksheet->getRowIterator() as $row){ 6 ?> 7 <tr> 8 <?php 9 $cellIterator = $row->getCellIterator(); 10 $cellIterator->setIterateOnlyExistingCells(false); 11 12 if( $i == 0 ){ 13 echo ‘<thead>‘; 14 } 15 foreach($cellIterator as $cell){ 16 17 echo ‘<td>‘ . $cell->getValue() . ‘</td>‘; 18 19 } 20 if( $i == 0 ){ 21 echo ‘</thead>‘; 22 } 23 $i++; 24 ?> 25 </tr> 26 <?php 27 } 28 ?> 29 </table> 复制代码
标签:
原文地址:http://www.cnblogs.com/wanlibingfeng/p/5528083.html