PHP操作EXCEL

PHPExcel

从 github 下载,几兆的包。

require_once ROOT . '/' . APP_DIR . '/Vendor/PHPExcel/IOFactory.php';
		
		
		$objPHPExcel = PHPExcel_IOFactory::load($this->filePath);
		$sheet = $objPHPExcel->getSheet(0);        // 读取第一个工作表(编号从 0 开始)
		$highestRow = $sheet->getHighestRow();           // 取得总行数
		$highestColumn = $sheet->getHighestColumn();   	
		
		$reader = $objPHPExcel->getWorksheetIterator();
		// 循环读取sheet
		foreach( $reader as $sheet ) {
			// 读取表内容
			$content = $sheet->getRowIterator();
			// 逐行处理
			$res_arr = array();
			foreach( $content as $key => $items ) {
				$rows = $items->getRowIndex(); // 行
				$columns = $items->getCellIterator(); // 列
				$row_arr = array();
				// 确定从哪一行开始读取
				if( $rows < 4 ) {
					continue;
				}
				// 逐列读取
				foreach( $columns as $head => $cell ) {
					// 获取cell中数据
					$data = $cell->getValue();
					echo $data;
					if('汇总信息'==$data) break 2;
					$row_arr[] = $data;
				}
				$res_arr[] = $row_arr;
			}
		}
原文地址:https://www.cnblogs.com/aworkstory/p/15266680.html