|
|
|
ถามเรื่องการ ຣiport file excel to php หน่อยค่ะ ขอถามเรื่อง import file excel to php |
|
|
|
|
|
|
|
คำนวณแบบรวจเดียวเลยหรอครับ นั้นสิทำไง ใครรู้บอกหน่อยครับผมก็อยากรู้เหมือนกัน
|
|
|
|
|
Date :
2009-08-14 22:57:01 |
By :
ต้น |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/myphp
$OpenFile = "MyXls/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("mydatabase");
for($i=2;$i<=5;$i++){
If(trim($xlSheet1->Cells->Item($i,1)) != "")
{
$strSQL = "";
$strSQL .= "INSERT INTO customer2 ";
$strSQL .= "(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$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)."') ";
mysql_query($strSQL);
}
}
//*** Close MySQL ***//
@mysql_close($objConnect);
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
Data Import/Inserted.
</body>
</html>
PHP Import Excel to Database
|
|
|
|
|
Date :
2009-08-14 23:03:37 |
By :
panyapol |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|