ช่วยเช็คโค๊ตด้วยค่ะ จะ export เป็น excel แต่มันฟ้อง Fatal error: Uncaught exception ค่ะ
Code (PHP)
<?
include "conn.inc.php";
$objDB = mysql_select_db("Fishery_db");
$strSQL = $sqlgetarea;
$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/landarea.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "Land Area";
$xlBook->Worksheets(1)->Select;
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A2")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("B4")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("C4")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("B7")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("C7")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("D7")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("E4")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("F6")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("F7")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("G7")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("H7")->ColumnWidth = 8.38;
$xlApp->ActiveSheet->Range("I7")->ColumnWidth = 8.38;
//*** Report Title ***//
$xlApp->ActiveSheet->Range("B2:I2")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("B2:I2")->MergeCells = True;
$xlApp->ActiveSheet->Range("B2:I2")->Font->Bold = True;
$xlApp->ActiveSheet->Range("B2:I2")->Font->Size = 10;
$xlApp->ActiveSheet->Range("B2:I2")->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(1,1)->Value = "Land Area, Length of Coastline and Inland Water Area";
//*** Header ***//
$xlApp->ActiveSheet->Cells(7,1)->Value = "Country, Sub-area";
$xlApp->ActiveSheet->Cells(7,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,1)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(7,2)->Value = "Year";
$xlApp->ActiveSheet->Cells(7,2)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,2)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,2)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,2)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(7,3)->Value = "Total land area (Km<sup>2</sup>)";
$xlApp->ActiveSheet->Cells(7,3)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,3)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,3)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,3)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(7,4)->Value = "Length of coastline (Km)";
$xlApp->ActiveSheet->Cells(7,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,4)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,4)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(7,5)->Value = "Reservoir";
$xlApp->ActiveSheet->Cells(7,5)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,5)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,5)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(7,6)->Value = "Lake";
$xlApp->ActiveSheet->Cells(7,6)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,6)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,6)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,6)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(7,7)->Value = "River";
$xlApp->ActiveSheet->Cells(7,7)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,7)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,7)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,7)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(7,8)->Value = "Other";
$xlApp->ActiveSheet->Cells(7,8)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(7,8)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,8)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(7,8)->BORDERS->Weight = 1;
//***********//
$intRows = 8;
while($objResult = mysql_fetch_array($objQuery))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["Country, Sub-area"];
$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["Year"];
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["Total land area (Km2)"];
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["Length of coastline (Km)"];
$xlApp->ActiveSheet->Cells($intRows,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["Reservoir"];
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,5)->NumberFormat = "$#,##0.00";
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["Lake"];
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,6)->NumberFormat = "$#,##0.00";
$xlApp->ActiveSheet->Cells($intRows,7)->Value = $objResult["River"];
$xlApp->ActiveSheet->Cells($intRows,7)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,7)->NumberFormat = "$#,##0.00";
$xlApp->ActiveSheet->Cells($intRows,8)->Value = $objResult["Other"];
$xlApp->ActiveSheet->Cells($intRows,8)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,8)->NumberFormat = "$#,##0.00";
$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($objConnect);
?>
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Office Excel<br/><b>Description:</b> Microsoft Office Excel cannot access the file 'C:\AppServ\www\statistical_bulletin\MyXls\202F6100'. 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\statistical_bulletin\gen_length_action.php:520 Stack trace: #0 C:\AppServ\www\statistical_bulletin\gen_length_action.php(520): variant->SaveAs('C:\AppServ\www\...') #1 {main} thrown in C:\AppServ\www\statistical_bulletin\gen_length_action.php on line 520
นี่คือบรรทัด 520 ค่ะ
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
ช่วยดูให้ด้วยนะคะขอบคุณค่ะTag : - - - -
Date :
2010-02-19 14:50:15
By :
Aea
View :
1481
Reply :
5
ขอโทษนะคะที่เข้ามาดูช้าแต่ยังงัยคะไม่ค่อยเข้าใจค่ะ แล้วเราจะแก้ยังงัยพยายามแก้มาหลายวันแล้วก็ยังแก้ไม่ได้เลยค่ะ
Date :
2010-02-26 10:47:27
By :
Aea
แก้ไม่ได้เหมือนกัน TT
Date :
2011-03-07 09:54:36
By :
emozerorise
ของผมก็เป็นเหมือนกันครับ จะexport sql เป็น Excel แบบว่า ถ้า run ในเครื่องผมมันทำได้ไม่มี ERROR แต่ถ้าขึ้น SV. แล้วมันจะฟ้อง ERROR
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in C:\AppServ\www\repair\rpexcel.php on line 45
ไม่เข้าใจเหมือนกัน ปัจจุบันก็ยังแก้ไม่ได้
https://www.thaicreate.com/php/forum/055349.html
Date :
2011-03-07 10:50:20
By :
yutthanagorn
Load balance : Server 01