PHP-ExcelReader

用于读取Excel文件的PHP Library。

 

DEMO:

 

 

 <?
	
	require_once 'Excel/reader.php';
	$data = new Spreadsheet_Excel_Reader ();
	
	$data->setOutputEncoding ( 'utf-8' );
	$data->read ( 'test.xls' );
	
	@ $db = mysql_connect ( 'localhost', 'root', 'pass' ) or die ( "Could not connect to database." );
	mysql_query ( "set names 'utf-8'" );
	mysql_select_db ( 'test' );
	
	error_reporting ( E_ALL ^ E_NOTICE );
	
	//$data->sheets[0]['numRows']为Excel行数
	for($i = 1; $i <= $data->sheets [1] ['numRows']; $i ++) {
		
		$sql = "INSERT INTO test VALUES('" . $data->sheets [1] ['cells'] [$i] [1] . "','" . $data->sheets [1] ['cells'] [$i] [2] . "')";
		echo $sql;
		echo "<br />";
		//插入数据库
		$res = mysql_query ( $sql );
		
		//$data->sheets[0]['numCols']为Excel列数
		for($j = 1; $j <= $data->sheets [1] ['numCols']; $j ++) {
			
			//显示每个单元格内容			
			echo $data->sheets [1] ['cells'] [$i] [$j];
			echo "<br />";
		}
	}
	?>

 

 

附件为ExcelReader CLASS!

你可能感兴趣的:(sql,mysql,PHP,Excel)