欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 读取excel

程序员文章站 2022-06-06 18:57:06
...
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() ."
"
}
}

   }

}

相关标签: php 读取excel