<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>excel—to—–mysql</title>
</head>
<body>
<?php
require_once ‘class/Excel/reader.php’; //加载所需类
$data = new Spreadsheet_Excel_Reader(); // 实例化
$data->setOutputEncoding(‘utf-8’); //设置编码
$data->read(‘xls/Study.xls’); //read函数读取所需EXCEL表,支持中文
$conn= mysql_connect(‘localhost’, ‘root’, ‘joyous’) or die(“数据库连接出错了。。。。”); //连接数据库
mysql_query(“set names ‘utf8′”);//设置编码输出
mysql_select_db(‘study’); //选择数据库
for ($i = 1; $i <= $data->sheets[0][‘numRows’]; $i++) {
$sql = “INSERT INTO excel VALUES(”,'”. $data->sheets[0][‘cells’][$i][2].”‘,'”. $data->sheets[0][‘cells’][$i][3].”‘)”;
echo $sql.'<br />’;
$insert = mysql_query($sql); //插入部分 注释掉,实际可以自己插入。
}
$sql=”select * from excel”;
$mysql=mysql_query($sql);
while($info=mysql_fetch_array($mysql))
{
echo $info[0].”—“.$info[1].”—“.$info[2].”<br />”;
}?>
</body>
最后说明下文件布局: 因为路径成败也是很大影响的 study文件夹包含了class文件夹(就是从那个压缩包解压出来的文件)、xls文件夹(里面是excel文件)、test.php文件 运行下text文件 然后看看数据库,是不是成功了呢?