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,027

HOME > PHP > PHP Forum > มีปัญาหาการ export ไฟล์ excel ครับ Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Unable to get the SaveAs property of the Workbook class'



 

มีปัญาหาการ export ไฟล์ excel ครับ Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Unable to get the SaveAs property of the Workbook class'

 



Topic : 041759



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



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




Code (PHP)
<? session_start(); ?>
<html>
<head><title>Report To Excel</title></head>
<body>
<table border=0 align=center width=800> 
		<tr>
			<td>
					<?	
					include "connect.php";
						include "check_user.php";
					?>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
<!-- convert month & year --><? ?>
<?
mysql_query( "use project" ); //or $objDB = mysql_select_db("evaluate");
if($_SESSION["SU_Status"]=='Administrator')// Show_plan code
	{
		$result=mysql_query("select * from course where Start_Date like '$_SESSION[syear]-$_SESSION[smonth]-%' order by Start_Date ");
	}
		else if($_SESSION["SU_Status"]=='Boss')
	{	$SU_ID = $_SESSION["SU_ID"];
		$result=mysql_query("select * from course where SU_ID = '$SU_ID'+4 and Start_Date like '$_SESSION[syear]-$_SESSION[smonth]-%' order by Start_Date ");
	}
	else if($_SESSION["SU_Status"]=='User')
	{	$SU_ID = $_SESSION["SU_ID"];
		$result=mysql_query("select * from course where SU_ID = $SU_ID and Start_Date like '$_SESSION[syear]-$_SESSION[smonth]-%' order by Start_Date ");
	}
if( $result )
{ 
//*** Get Document Path ***//
$strPath = realpath( "/AppServ/www/Project" );

//*** Excel Document Root ***//
$strFileName = "Report/รายงาน$_SESSION[SU_User] $_SESSION[smonth] $_SESSION[syear].xls";

//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();


//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "Report"; 
$xlBook->Worksheets(1)->Select;

//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 23.0;
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("G1:G1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("H1:H1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("I1:I1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("J1:J1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("K1:K1")->ColumnWidth = 12.0;

//*** Report Title ***//
$xlApp->ActiveSheet->Range("A1:K1")->BORDERS->Weight = 2;
$xlApp->ActiveSheet->Range("A1:K1")->MergeCells = True;
$xlApp->ActiveSheet->Range("A1:K1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("A1:K1")->Font->Name = "Angsana New";
$xlApp->ActiveSheet->Range("A1:K1")->Font->Size = 18;
$xlApp->ActiveSheet->Range("A1:K1")->HorizontalAlignment = -4108; 
$xlApp->ActiveSheet->Cells(1,1)->Value = "สรุปผลการประเมินการฝึกอบรม งวดเดือน$_SESSION[smonth] / $_SESSION[syear]";

//*** Header ***// 
$xlApp->ActiveSheet->Range("A2:K2")->BORDERS->Weight = 2;
$xlApp->ActiveSheet->Range("A2:K2")->Font->Bold = True;
$xlApp->ActiveSheet->Range("A2:K2")->Font->Name = "Angsana New";
$xlApp->ActiveSheet->Range("A2:K2")->Font->Size = 16;
$xlApp->ActiveSheet->Range("A2:K2")->HorizontalAlignment = -4108; 
$xlApp->ActiveSheet->Range("A2:K2")->VerticalAlignment = -4108; 
$xlApp->ActiveSheet->Cells(2,1)->Value = "ชื่อหลักสูตรหัวข้อวิชา";

$xlApp->ActiveSheet->Cells(2,2)->Value = "วันเริ่มต้น";

$xlApp->ActiveSheet->Cells(2,3)->Value = "วันสุดท้าย";

$xlApp->ActiveSheet->Cells(2,4)->Value = "ชื่อสถานที่";

$xlApp->ActiveSheet->Cells(2,5)->Value = "จำนวนผู้ฝึกอบรม";

$xlApp->ActiveSheet->Cells(2,6)->Value = "ด้านวิทยากร";

$xlApp->ActiveSheet->Cells(2,7)->Value = "ด้านเนื้อหา";

$xlApp->ActiveSheet->Cells(2,8)->Value = "ด้านบริการ";

$xlApp->ActiveSheet->Cells(2,9)->Value = "ค่าเฉลี่ยรวม";

$xlApp->ActiveSheet->Cells(2,10)->Value = "ความเหมาะสะสมด้านเวลา";

$xlApp->ActiveSheet->Cells(2,11)->Value = "ร้อยละแบบประเมินที่ได้รับ";

$xlApp->ActiveSheet->Range( "A3:K3" )->BORDERS->Weight = 2;
$xlApp->ActiveSheet->Range( "A3:K3" )->MergeCells = True;
$xlApp->ActiveSheet->Range("A3:K3")->Font->Name = "Angsana New";
$xlApp->ActiveSheet->Range("A3:K3")->Font->Size = 16;
$xlApp->ActiveSheet->Range( "A3:K3" )->Font->Bold = True;
$xlApp->ActiveSheet->Range( "A3:K3" )->VerticalAlignment = -4108; 
$xlApp->ActiveSheet->Range( "A3:K3" )->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->Value = $_SESSION['username'] . ".";

//***********//

$intRows = 4;
while( $rec = mysql_fetch_array( $result ) )
{
	//*** Detail ***//	
	if( $rec['Generation'] == '0' )
{
	$xlApp->ActiveSheet->Cells($intRows,1)->Value = $rec['Course_Name'] . " / " . $rec['Subject_Name'];
	$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 2;
	$xlApp->ActiveSheet->Cells($intRows,1)->EntireColumn->AutoFit;	
}
else
{
	$xlApp->ActiveSheet->Cells($intRows,1)->Value = $rec['Course_Name'] . " / " . $rec['Subject_Name'] . " รุ่นที่ " . $rec['Generation'];
	$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 2;
	$xlApp->ActiveSheet->Cells($intRows,1)->EntireColumn->AutoFit;	
}

$Syear=substr("$rec[Start_Date]",0,4); // Start date
$Smonth=substr("$rec[Start_Date]",5,2);
$Sdate=substr("$rec[Start_Date]",8,9);
$Eyear=substr("$rec[End_Date]",0,4); // End date
$Emonth=substr("$rec[End_Date]",5,2);
$Edate=substr("$rec[End_Date]",8,9);

$xlApp->ActiveSheet->Cells($intRows,2)->Value = "$Sdate/$Smonth/$Syear";
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 2;

$xlApp->ActiveSheet->Cells($intRows,3)->Value = "$Edate/$Emonth/$Eyear";
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 2;

$xlApp->ActiveSheet->Cells($intRows,4)->Value = $rec['Location'];
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 2;
$xlApp->ActiveSheet->Cells($intRows,4)->EntireColumn->AutoFit;

$xlApp->ActiveSheet->Cells($intRows,5)->Value = $rec['Amount'];
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 2;

$sql = mysql_query( "select AVG(Pointa1), AVG(Pointa2), AVG(Pointa3), AVG(Pointa4), AVG(Pointb1), AVG(Pointb2), AVG(Pointb3), AVG(Pointc1), AVG(Pointc2), AVG(Pointc3), AVG(Pointc4), AVG(Point_Overall) from evaluate_general where Course_ID = $rec[Course_ID] " );
$point = mysql_fetch_array( $sql );
$avggroup1 = ( $point[0]+$point[1]+$point[2]+$point[3] ) / 4;//คำนวนหาค่าเฉลี่ยต่อหมวด
$avggroup2 = ( $point[4]+$point[5]+$point[6] ) / 3;
$avggroup3 = ( $point[7]+$point[8]+$point[9]+$point[10] ) / 4;
$avgall = ( $point[0] + $point[1] + $point[2] + $point[3] + $point[4] + $point[5] + $point[6] + $point[7] + $point[8] + $point[9] + $point[10] + $point[11] + $point[12] ) / 12;//คำนวณหาค่าเฉลี่ยรวม
$avg1 = round( $avggroup1, 2 );
$avg2 = round( $avggroup2, 2 );
$avg3 = round( $avggroup3, 2 );
$avg_all = round( $avgall, 2 );

$xlApp->ActiveSheet->Cells($intRows,6)->Value = $avg1;
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 2;

$xlApp->ActiveSheet->Cells($intRows,7)->Value = $avg2;
$xlApp->ActiveSheet->Cells($intRows,7)->BORDERS->Weight = 2;

$xlApp->ActiveSheet->Cells($intRows,8)->Value = $avg3;
$xlApp->ActiveSheet->Cells($intRows,8)->BORDERS->Weight = 2;

$xlApp->ActiveSheet->Cells($intRows,9)->Value = $avg_all;
$xlApp->ActiveSheet->Cells($intRows,9)->BORDERS->Weight = 2;

$p13 = mysql_fetch_array( mysql_query("select count(Time) from evaluate_general where Course_ID = $rec[Course_ID] ") );//นับใบประเมินทั้งหมดของหลักสูตรนี้
if ($p13[0]=='0')//กรณีที่ นับจำนวนใบประสานงานแล้วมีค่าเป็น 0
{
	$p13[0]=1;//กำหนดค่า ให้เป็น 1 เพราะตัวหารไม่สามารถมีค่าเป็น0ได้
}
$p13good = mysql_fetch_array( mysql_query("select count(Time) from evaluate_general where Course_ID = $rec[Course_ID] and Time ='1' ") );//หาจำนวนใบที่เหมาะสม
$pergood = $p13good[0]*100/$p13[0]; //คำนวนเป็นเปอร์เซ็น
$per_good = round($pergood,2);
$xlApp->ActiveSheet->Cells($intRows,10)->Value = $per_good;
$xlApp->ActiveSheet->Cells($intRows,10)->BORDERS->Weight = 2;

$numeva = mysql_num_rows(mysql_query("select * from evaluate_general where Course_ID = $rec[Course_ID] "));//นับใบประเมิน
$pereva=$numeva*100/$rec[Amount];
$per_eva = round( $pereva,2 );
$xlApp->ActiveSheet->Cells($intRows,11)->Value = $per_eva;
$xlApp->ActiveSheet->Cells($intRows,11)->BORDERS->Weight = 2;

$intRows++;
} // End while

@unlink($strFileName); //*** Delete old files ***// 

$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//

//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;

} // End if
?>

<tr><td align = center><b><a href="<?=$strFileName?>">คลิ๊กเพื่อดาวน์โหลด</a> รายงานสรุปผลการประเมินการฝึกอบรม ประจำเดือน <? echo "$_SESSION[smonth] / $_SESSION[syear]" ?></b></td></tr>
</table>
</body>
</html>


ผมได้เขียนโค้ดตามนี้ พอลองเปิด มันก็ขึ้นเออเร่อครับ

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Unable to get the SaveAs property of the Workbook class' in C:\AppServ\www\Project\report_general_excel.php:191 Stack trace: #0 C:\AppServ\www\Project\report_general_excel.php(191): variant->SaveAs('C:\AppServ\www\...') #1 {main} thrown in C:\AppServ\www\Project\report_general_excel.php on line 191

ไม่ทราบว่าผิดตรงไหนครับ

รบกวนด้วยนะครับ

ขอบคุณมากครับ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-04-21 10:51:46 By : l3oatsu View : 2287 Reply : 10
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

ลองเอาจากตัวอย่างแล้วค่อย ๆ แก้ทีล่ะจุดครับ เพราะ error ของ excel ค่อนข้างจะ debug ยากครับ

Go to : PHP Excel (Excel.Application) : การใช้งาน PHP กับ Microsoft Excel






Date : 2010-04-21 12:17:52 By : webmaster
 


 

No. 2



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



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


ขอบคุณครับ จะลองไปทำดูนะครับ
Date : 2010-04-21 13:22:07 By : l3oatsu
 

 

No. 3



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



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


เพิ่มเติมครับ

ผมทำใน windows 7 ก็ขึ้นเออเร่อตามที่บอกไว้ครับ

แต่พอไปลองรันในเครื่องอื่นที่ใช้ windows xp ได้แล้วครับ

เห็นมีคนเคยเป็นแบบนี้เหมือนกัน อาการเดียวกับผมเลย

คาดว่าน่าจะเป็นที่ตัววินโดว์ นะครับ
Date : 2010-04-23 14:38:28 By : l3oatsu
 


 

No. 4



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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


โหลด PHP_Excel มาใช้ดีกว่าครับ ใช้ได้ทั้ง Windows และ Linux
Date : 2010-04-23 14:49:08 By : plakrim
 


 

No. 5



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



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

PHP_Excel สามารถสร้างกราฟได้ป่าวครับ

Date : 2011-03-07 11:02:03 By : emozerorise
 


 

No. 6



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

เดียวขอปรับ Code ให้รองรับ Windows 7 ด้วยดีกว่า
Date : 2011-03-07 11:34:54 By : webmaster
 


 

No. 7



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



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

ขอดูด้วยน่ะครับ ^^
Date : 2011-03-08 10:02:52 By : emozerorise
 


 

No. 8

Guest


แก้ไม่ถูกเลยเป็นเหมือนกัน
Date : 2011-09-12 09:57:31 By : bigcrazie
 


 

No. 9



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

ภายใน 1-2 วันนี้จะปรับให้รองรับ Office 2007 + Windows 7 ครับ เสร็จแล้วเดียวจะนำมาโพสให้ครับ
Date : 2011-09-12 10:11:39 By : webmaster
 


 

No. 10



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

Quote:
Unable to get the SaveAs property of the Workbook class'


Go to : Unable to get the Open property of the Workbooks class (Excel 2003, 2007 Automation on Windows 2008 Server)
Date : 2012-11-30 21:20:12 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : มีปัญาหาการ export ไฟล์ excel ครับ Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Unable to get the SaveAs property of the Workbook class'
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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