|
|
|
PHP Import Excel to Database (Excel.Application) ทำตามแล้วมันไม่ได้อะคับ |
|
|
|
|
|
|
|
ช่วยดูให้หน่อยเถอะคับ มันผิดตรงไหนหว๋าาาา
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
</head>
<body>
<?
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/satisfy/
$OpenFile = "MyCustomer.xls";
//*** Create Exce.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
//$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile));
$xlSheet1 = $xlBook->Worksheets(1);
//*** Insert to MySQL Database ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("db_satisfy");
for($i=2;$i<=5;$i++){
If(trim($xlSheet1->Cells->Item($i,1)) != "")
{
$strSQL = "";
$strSQL .= "INSERT INTO customer ";
$strSQL .= "(CustomerID,CustCode,CustId,CompanyName_EN,CompanyName_TH,ContactAddress,ContactAddress2,ContactAddress3,ContactAddress4,ContactAddress5,
CustPhone,CustFax,CustEMail,ContactPerson1,ContactPerson2,CustDepartment,CustDiscoveRate,BTypeID,CTypeID,TermOfPayment,date_connect,cust_source,
EmpID,event,CustQuoNo,CustPJ,Form_status,InquireCode) ";
$strSQL .= "VALUES ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,1)."','".$xlSheet1->Cells->Item($i,2)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,3)."','".$xlSheet1->Cells->Item($i,4)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,5)."','".$xlSheet1->Cells->Item($i,6)."') ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,7)."','".$xlSheet1->Cells->Item($i,8)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,9)."','".$xlSheet1->Cells->Item($i,10)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,11)."','".$xlSheet1->Cells->Item($i,12)."') ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,13)."','".$xlSheet1->Cells->Item($i,14)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,15)."','".$xlSheet1->Cells->Item($i,16)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,17)."','".$xlSheet1->Cells->Item($i,18)."') ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,19)."','".$xlSheet1->Cells->Item($i,20)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,21)."','".$xlSheet1->Cells->Item($i,22)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,23)."','".$xlSheet1->Cells->Item($i,24)."') ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,25)."','".$xlSheet1->Cells->Item($i,26)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,27)."','".$xlSheet1->Cells->Item($i,28)."') ";
mysql_query($strSQL);
}
}
//*** Close MySQL ***//
@mysql_close($objConnect);
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
Data Import/Inserted.
</body>
</html>
Tag : - - - -
|
|
|
|
|
|
Date :
2010-01-07 15:58:51 |
By :
maruk |
View :
1213 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
วงเล็บบรรทัดที่29-40 ลองดูใหม่
|
|
|
|
|
Date :
2010-09-06 16:14:19 |
By :
napat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|