export sql to excel มีปัญหาครับ มันขึ้น error ไม่รู้ว่ามันคืออะไร(เพิ่งหัดใช้ครับ)
Quote: 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\3bb\WorkOrder\export_ADMIN.php:70 Stack trace: #0 C:\AppServ\www\3bb\WorkOrder\export_ADMIN.php(70): variant->SaveAs('C:\AppServ\www\...') #1 {main} thrown in C:\AppServ\www\3bb\WorkOrder\export_ADMIN.php on line 70
มันขึ้นข้อความแบบนี้อ่ะครับ ผมเพิ่งหัดใช้ครั้งแรก เลยไม่รู้ว่ามันคืออะไร แก้ไม่ถูกด้วยครับ
โค้ดที่ใช้
Code (PHP)
<?
session_start();
if ($_SESSION['ADMINID'] == "") { //ถ้าตัวแปรเป็นค่า ว่าง
header("Location:../index.php"); //ให้ไปหน้า login
}
include("../connect.php");
mysql_query("SET character_set_results=UTF8");
mysql_query("SET character_set_client=UTF8");
mysql_query("SET character_set_connection=UTF8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?
$strSQL = "SELECT * FROM workorder";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "MyXls/WorkList.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "Work List";
$xlBook->Worksheets(1)->Select;
//*** Header ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "IDwork";
$xlApp->ActiveSheet->Cells(1,2)->Value = "work";
$xlApp->ActiveSheet->Cells(1,3)->Value = "date";
$xlApp->ActiveSheet->Cells(1,4)->Value = "worker1";
$xlApp->ActiveSheet->Cells(1,5)->Value = "position1";
$xlApp->ActiveSheet->Cells(1,6)->Value = "detail";
$xlApp->ActiveSheet->Cells(1,7)->Value = "status";
$xlApp->ActiveSheet->Cells(1,8)->Value = "detail_un";
$xlApp->ActiveSheet->Cells(1,9)->Value = "UserID";
$xlApp->ActiveSheet->Cells(1,10)->Value = "fname";
//***********//
$intRows = 2;
while($objResult = mysql_fetch_array($objQuery))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["IDwork"];
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["work"];
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["date"];
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["worker1"];
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["position1"];
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["detail"];
$xlApp->ActiveSheet->Cells($intRows,7)->Value = $objResult["status"];
$xlApp->ActiveSheet->Cells($intRows,8)->Value = $objResult["detail_un"];
$xlApp->ActiveSheet->Cells($intRows,9)->Value = $objResult["UserID"];
$xlApp->ActiveSheet->Cells($intRows,10)->Value = $objResult["fname"];
$intRows++;
}
@unlink($strFileName); //*** Delete old files ***//
$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
//$xlBook->SaveAs(realpath($strFileName)); //*** Save to Path ***//
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
}
mysql_close();
?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
</body>
</html>
Tag : PHP, MySQL, Excel (Excel.Application)
Date :
2012-03-14 11:56:02
By :
akkaneetha
View :
1196
Reply :
2
Code ในบทความของผมยังเป็น Version Office 2003 ครับ ถ้ารันบน 2007 น่าจะไม่ได้ครับ
Date :
2012-03-14 12:37:13
By :
webmaster
แล้วพอจะมีวิธีแก้มั้ยครับ
Date :
2012-03-14 13:56:22
By :
akkaneetha
Load balance : Server 04