摘要:phpexcel套件寫入mysql
內文
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>
</head>
<body>
<?
$host = "localhost";
$link = mysql_connect($host, "root", "660168");
mysql_query("SET NAMES 'utf8'");
mysql_select_db("test", $link);
require_once 'Excel/reader.php'; //注意這裡的引用位置
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('utf-8'); //指定編碼很重要
$data->read("test2.xls");
//error_reporting(E_ALL ^ E_NOTICE);
mysql_query('set names "utf-8"'); //指定編碼很重要
for ($i = 1; $i <= $data-> sheets[0][ 'numRows']; $i++) {
$sql = "INSERT INTO test(subject) VALUES('". $data->sheets[0]['cells'][$i][1]."')";//開始讀取excel文件的內容並插入數據庫
echo $data->sheets[0]['cells'][$i][1];
mysql_query($sql);
}
<?
$host = "localhost";
$link = mysql_connect($host, "root", "660168");
mysql_query("SET NAMES 'utf8'");
mysql_select_db("test", $link);
require_once 'Excel/reader.php'; //注意這裡的引用位置
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('utf-8'); //指定編碼很重要
$data->read("test2.xls");
//error_reporting(E_ALL ^ E_NOTICE);
mysql_query('set names "utf-8"'); //指定編碼很重要
for ($i = 1; $i <= $data-> sheets[0][ 'numRows']; $i++) {
$sql = "INSERT INTO test(subject) VALUES('". $data->sheets[0]['cells'][$i][1]."')";//開始讀取excel文件的內容並插入數據庫
echo $data->sheets[0]['cells'][$i][1];
mysql_query($sql);
}
?>
</body>
</html>
</body>
</html>