Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > PHP > PHP Forum > excel app Fatal error: Uncaught exception 'com_exception' เป็นเพราะอะไรครับ


[PHP] excel app Fatal error: Uncaught exception 'com_exception' เป็นเพราะอะไรครับ

 
Topic : 116677



โพสกระทู้ ( 158 )
บทความ ( 0 )



สถานะออฟไลน์



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)
01.<html>
02.<head>
03.<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
04.<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
05.<body>
06.<?php
07.set_time_limit(0);
08.    //*** Get Document Path ***//
09.    $strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
10.    $OpenFile = "MyXls/18-05-2015.xlsx";
11.    //*** Create Exce.Application ***//
12.    $xlApp = new COM("Excel.Application", NULL, CP_UTF8) or Die ("Did not instantiate Excel");
13.    $xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
14.    //$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile));
15. 
16.    $xlSheet1 = $xlBook->Worksheets(1); 
17.    $count = $xlSheet1->UsedRange->Rows->Count();
18.    //*** Insert to MySQL Database ***//
19.     
20.    include "conex.php";
21.    $PlanDate = $xlSheet1->Cells->Item(1,1);
22.    $lp = strlen($PlanDate);
23.    $planD = substr($PlanDate, 62, $lp);
24.    $newplanD = ereg_replace('[[:space:]]+', ' ', trim($planD));
25.    for($i=5;$i<=150;$i++){
26.        if(trim($xlSheet1->Cells->Item($i,2)) != "")
27.        {
28.            $weight = number_format( $xlSheet1->Cells->Item($i,13) , 2 );
29. 
30.             
31.            $strSQL = "";
32.            $strSQL .= "INSERT INTO plantable ";
33.            $strSQL .= "(NO,PRD,SO,CusName,ProName,Weight,ShipDate,OrderNum,ShipNum,CarReg,PlanDate,M) ";
34.            $strSQL .= "VALUES ";
35.            $strSQL .= "('".$xlSheet1->Cells->Item($i,2)."','".$xlSheet1->Cells->Item($i,4)."','".$xlSheet1->Cells->Item($i,5)."' ";
36.            $strSQL .= ",'".$xlSheet1->Cells->Item($i,6)."','".$xlSheet1->Cells->Item($i,10)."' ";
37.            $strSQL .= ",'$weight','".$xlSheet1->Cells->Item($i,16)."' ";
38.            $strSQL .= ",'".$xlSheet1->Cells->Item($i,17)."','".$xlSheet1->Cells->Item($i,18)."','".$xlSheet1->Cells->Item($i,26)."','$newplanD','".$xlSheet1->Cells->Item($i,12)."') ";
39.            mysql_query($strSQL);
40.        }
41.         
42.    }
43.     
44.     
45.     
46.    //*** Close MySQL ***//
47.    @mysql_close($objConnect);
48. 
49.    //*** Close & Quit ***//
50.    $xlApp->Application->Quit();
51.    $xlApp = null;
52.    $xlBook = null;
53.    $xlSheet1 = null;
54.?>
55.Data Import/Inserted.
56.</body>
57.</html>




Tag : PHP

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-05-22 09:27:43 By : dekcomwat View : 1448 Reply : 1
 

 

No. 1



โพสกระทู้ ( 9,590 )
บทความ ( 2 )



สถานะออฟไลน์


ก่อนจะเปิดไฟล์ มาใช้ เช็คก่อนว่ามีไฟล์อยู่จริง

Code
if( !file_exists( $strPath."/".$OpenFile )) die ( "File not found [$strPath/$OpenFile]"); 13.$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);


ถ้ายัง error อยู่ ค่อยว่ากันต่อ


ประวัติการแก้ไข
2015-05-22 09:44:50
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-05-22 09:43:56 By : Chaidhanan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : excel app Fatal error: Uncaught exception 'com_exception' เป็นเพราะอะไรครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่