php mysql 滙入excel(完整版)d

摘要:php mysql 滙入excel(完整版)d

pro20.html

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>Jquery</title>
 
</head>
 
<body >
<table width="98%" border="0" align="center" style="margin-top:20px; border:1px solid #9abcde;">
<form id="form1" name="form1" enctype="multipart/form-data" method="POST" action="store_add.php">
 
<tr >
<td height="28" colspan="2" background=" "><label> <strong><a href="#">檔案上傳
</a></strong></label></td>
</tr>
<tr>
<td width="18%" height="50"> 選擇你要導入的Excel資料表</td>
<input name="file" type="file" id="file" size="50" />
</label>
<label>
<input name="button" type="submit" class="nnt_submit" id="button" value="導入資料" onclick="import_check();"/> 
</label>
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#DDF0FF"> [<span class="STYLE1">注</span>]資料表導入格式說明:</td>
</tr>
<tr>
<td colspan="2"> 1、其它.導入資料表文件必須是<strong>excel</strong>文件格式{.<span class="STYLE2">xls</span>}
 
為副檔名. </td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<tr> <tr>
<td colspan="2"> </td>
</tr></form>
</table> 
</body>
</html>
 
 
store_add.php
 
 $Import_TmpFile = $_FILES['file']['name'];
  
   echo "Import_TmpFile = ".$Import_TmpFile."<br>";
   move_uploaded_file($_FILES['file']['tmp_name'],"uploads/".$_FILES['file']['name']);
 
      require_once('phpExcelReader/Excel/reader.php');
    $data = new Spreadsheet_Excel_Reader();
    $data->setOutputEncoding('UTF-8');
    $data->read("uploads/".$_FILES['file']['name']);
    $array =array();
 
echo $data->sheets[0]['numRows']."<br>";
echo $data->sheets[0]['numCols']."<br>";
 
 
    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
    for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
    $array[$i][$j] = $data->sheets[0]['cells'][$i][$j];
    }
    }
 
$num = $data->sheets[0]['numRows'];
for($i=1;$i<=$num;$i++)
{
 $sql = "insert into adminstore (StoreName,StoreAdd,Storephone) values('".$array[$i][1]."','".$array[$i][2]."','".$array[$i][3]."')";
 echo $sql."<br>";
mysql_query($sql);
}