|
 |
|
อยากทราบว่า โค้ดนี้ถูกต้องมั้ยอ่ะครับ เกี่ยวกับ export to excel ช่วยดูให้ทีนะครับ |
|
 |
|
|
 |
 |
|
พอดีติดที่ว่า ผมไม่สามารถรันได้ เพราะ โค้ด export to excel ของเว็บนี้ไม่รองรับ win7 กับ office 2007 ครับ
แต่แค่อยากรู้ว่า โค้ดนี้พอที่จะถูกต้องมั้ยครับ
ขอบคุณไว้ ณ ที่นี้ครับ
Code (PHP)
<?
echo $sort=$_GET['sort'];
echo $order=$_GET['order'];
echo $ddlSelect=$_GET['ddlSelect'];
echo $txtKeyword=$_GET['txtKeyword'];
echo $txtKeyword2=$_GET['txtKeyword2'];
$strSQL = "SELECT * FROM workorder WHERE '".$_GET['ddlSelect']."' = '".$_GET['txtKeyword']."' ORDER BY '".$_GET['sort']."' ".$order." "; // โค้ดนี้ ถูกต้องตาม syntex มั้ยครับ จะทำงานได้มั้ย
$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.
Tag : PHP, MySQL, JavaScript, Excel (Excel.Application)

|
|
 |
 |
 |
 |
Date :
2012-03-15 14:31:47 |
By :
akkaneetha |
View :
878 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่น่าจะได้ครับ เดียวว่าง ๆ จะลองแก้ไขให้มันใช้ได้กับ Office 2007 ให้ครับ 
|
 |
 |
 |
 |
Date :
2012-03-16 06:23:00 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|