 |
|
Error ที่มันแจ้งครับ
Quote:Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Excel<br/><b>Description:</b> Microsoft Excel cannot access the file 'C:\AppServ\www\ajaxupload\MyXls\18-05-2015.xlsx'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook.' in C:\AppServ\www\ajaxupload\chkex.php:13 Stack trace: #0 C:\AppServ\www\ajaxupload\chkex.php(13): variant->Open('C:\AppServ\www\...') #1 {main} thrown in C:\AppServ\www\ajaxupload\chkex.php on line 13
นี้ code ของผม
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<?php
set_time_limit(0);
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$OpenFile = "MyXls/18-05-2015.xlsx";
//*** Create Exce.Application ***//
$xlApp = new COM("Excel.Application", NULL, CP_UTF8) or Die ("Did not instantiate Excel");
$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
//$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile));
$xlSheet1 = $xlBook->Worksheets(1);
$count = $xlSheet1->UsedRange->Rows->Count();
//*** Insert to MySQL Database ***//
include "conex.php";
$PlanDate = $xlSheet1->Cells->Item(1,1);
$lp = strlen($PlanDate);
$planD = substr($PlanDate, 62, $lp);
$newplanD = ereg_replace('[[:space:]]+', ' ', trim($planD));
for($i=5;$i<=150;$i++){
if(trim($xlSheet1->Cells->Item($i,2)) != "")
{
$weight = number_format( $xlSheet1->Cells->Item($i,13) , 2 );
$strSQL = "";
$strSQL .= "INSERT INTO plantable ";
$strSQL .= "(NO,PRD,SO,CusName,ProName,Weight,ShipDate,OrderNum,ShipNum,CarReg,PlanDate,M) ";
$strSQL .= "VALUES ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,2)."','".$xlSheet1->Cells->Item($i,4)."','".$xlSheet1->Cells->Item($i,5)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,6)."','".$xlSheet1->Cells->Item($i,10)."' ";
$strSQL .= ",'$weight','".$xlSheet1->Cells->Item($i,16)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,17)."','".$xlSheet1->Cells->Item($i,18)."','".$xlSheet1->Cells->Item($i,26)."','$newplanD','".$xlSheet1->Cells->Item($i,12)."') ";
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 : PHP
|
|
 |
 |
 |
 |
Date :
2015-05-22 09:27:43 |
By :
dekcomwat |
View :
1457 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |