?? example.php.bak
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 輸出excel </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<BODY>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<?php
require_once 'Excel/reader.php';
require "conn.php";
// ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('GB2312');
/***
* if you want you can change 'iconv' to mb_convert_encoding:
$data->setUTFEncoder('mb');
*
**/
/***
* By default rows & cols indeces start with 1
* For change initial index use:
* $data->setRowColOffset(0);
*
**/
/***
* Some function for formatting output.
* $data->setDefaultFormat('%.2f');
* setDefaultFormat - set format for columns with unknown formatting
*
* $data->setColumnFormat(4, '%.3f');
* setColumnFormat - set format for column (apply only to number fields)
*
**/
$data->read('./upload\\1.xls');
/*
$data->sheets[0]['numRows'] - count rows
$data->sheets[0]['numCols'] - count columns
$data->sheets[0]['cells'][$i][$j] - data from $i-row $j-column
$data->sheets[0]['cellsInfo'][$i][$j] - extended info about cell
$data->sheets[0]['cellsInfo'][$i][$j]['type'] = "date" | "number" | "unknown"
if 'type' == "unknown" - use 'raw' value, because cell contain value with format '0.00';
$data->sheets[0]['cellsInfo'][$i][$j]['raw'] = value if cell without format
$data->sheets[0]['cellsInfo'][$i][$j]['colspan']
$data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
*/
error_reporting(E_ALL ^ E_NOTICE);
$link=MySQL_connect($host_name,$db_user,$db_password)or die("與服務器連接失??!");
MySQL_select_db($db_name,$link)or die("提示:沒有找到數據庫!");
MySQL_query("set names gb2312");
$array=array("0","1","2","3","4","5","6","7","8","9");
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$array[$j]=$data->sheets[0]['cells'][$i][$j];
echo "\"".$data->sheets[0]['cells'][$i][$j]."\",";
}
echo "<p>";
if($link)
{
$sql="insert into classroom values('".$array[1]."','".$array[1]."','".$array[2]."','".$array[3]."','".$array[4]."')";
$result=mysql_query($sql);
if($result)
{
echo "<p>數據插入成功!";
}
else
{
echo "<p>數據插入失敗!";
}
}
echo "<p>";
}
//print_r($data);
//print_r($data->formatRecords);
?>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -