日期:2014-05-17 浏览次数:20426 次
<?php
require_once 'reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('gbk');
$data->read('in.xls');
@ $db = mysql_connect('localhost', 'root', '123456') or
die("Could not connect to database.");
mysql_query("set names 'gbk'");
mysql_select_db('test1');
error_reporting(E_ALL ^ E_NOTICE);
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
$a = $data->sheets[0]['cells'][$i][1];//取得第一列的数据
$b = $data->sheets[0]['cells'][$i][2];//取得第二列的数据
$c = $data->sheets[0]['cells'][$i][3];//取得第三列的数据
$d = $data->sheets[0]['cells'][$i][4];//取得第四列的数据
$e = $data->sheets[0]['cells'][$i][5];//取得第五列的数据
$f = $data->sheets[0]['cells'][$i][6];//取得第六列的数据
$g = $data->sheets[0]['cells'][$i][7];//取得第七列的数据
$sql = "INSERT INTO appexp (account,appinfo,price,result,income,pay,date) VALUES('$a','$b','$c','$d','$e','$f','$g')";
echo $sql.'<br />';
$res = mysql_query($sql) or die ("错误:$sql");
}
?>
<?php
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
if($_FILES){
$check = substr($_FILES["file"]["name"],strrpos($_FILES["file"]["name"],".")+1);
if ( $check == "xls"
------解决方案--------------------
$check == "xlsx")
{
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
}
else
{
exit('no');
}
$data->setOutputEncoding('UTF-8');
$data->read("upload/" . $_FILES["file"]["name"]);
error_reporting(E_ALL ^ E_NOTICE);
$db_host = 'localhost'; //edit_config
$db_user = 'root';
$db_password = 'root';
$db_port = 3306;
$db_name = 'test';
$con = mysql_connect($db_host,$db_user,$db_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($db_name, $con);
if (!$db_selected)
{
die ("Can\'t use test_db : " . mysql_error());