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['numRows']为Excel行数
for($i = 1; $i <= $data->sheets ['numRows']; $i ++) {
$sql = "INSERT INTO test VALUES('" . $data->sheets ['cells'] [$i] . "','" . $data->sheets ['cells'] [$i] . "')";
echo $sql;
echo "<br />";
//插入数据库
$res = mysql_query ( $sql );
//$data->sheets['numCols']为Excel列数
for($j = 1; $j <= $data->sheets ['numCols']; $j ++) {
//显示每个单元格内容
echo $data->sheets ['cells'] [$i] [$j];
echo "<br />";
}
}
?>
附件为ExcelReader CLASS!
页:
[1]