Home > Backend Development > PHP Tutorial > php 读取excel

php 读取excel

WBOY
Release: 2016-06-23 14:34:55
Original
910 people have browsed it

php读取excel,  用phpexcel,

我是在window环境下开发的,所以匹配php.ini

zlib.output_compression = On,(从off变成On)

扩展:

extension=php_xmlrpc.dll
extension=php_zip.dll

这2个要启用

 

然后,在此下载 http://phpexcel.codeplex.com/

 

 

//加载类库

require_once( ROOT_PATH . '/includes/libraries/phpreader/Classes/PHPExcel/IOFactory.php');

 

//2007版本的excel文件用 'Excel2007',07以下的版本用Excel5

 // $objReader = PHPExcel_IOFactory::createReader('Excel2007');

  $objReader = PHPExcel_IOFactory::createReader('Excel5');
            $objPHPExcel = $objReader->load('test.xls');

 

//读sheet

foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {

//读某个sheet的行数据

    foreach ($worksheet->getRowIterator() as $row) {

      //循环读取每个cell的数据

        foreach ($cellIterator as $k => $cell) {
                       if (!is_null($cell) ) {
                    
                         echo $cell->getCalculatedValue()  ."
"
                     }
                }

 

    }

}





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template