php 读取excel
我是在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() ."
"
}
}
}
}