|
 |
|
รบกวนสอบถามเรื่องนำค่าจากฐานข้องมูล MSSQL มา Export เป็น Excel จะต้องทำอย่างไงบ้างครับ |
|
 |
|
|
 |
 |
|
ใช้ PHPExcel ครับ สุดยอดไปเลยครับตัวนี้
|
 |
 |
 |
 |
Date :
2013-03-06 10:58:38 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนอีกเรื่องครับบ แล้วพวกโค้ดนี่หละครับเราจะทำไงบ้าง พอดีผมเพิ่งเริ่มหัดเขียนอะครับ
|
 |
 |
 |
 |
Date :
2013-03-06 11:07:59 |
By :
JonERom3O |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันจะแปปลงอย่างไงอะครับ ผมใช้ MicrosoftSQL อะครับ
|
 |
 |
 |
 |
Date :
2013-03-06 11:13:28 |
By :
JonERom3O |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
</head>
<body>
<?
$objConnect = mssql_connect("localhost","sa","") or die("Error Connect to Database");
$objDB = mssql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "MyXls/MyExcel.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "My Customer";
$xlBook->Worksheets(1)->Select;
//*** Header ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "CustomerID";
$xlApp->ActiveSheet->Cells(1,2)->Value = "Name";
$xlApp->ActiveSheet->Cells(1,3)->Value = "Email";
$xlApp->ActiveSheet->Cells(1,4)->Value = "CountryCode";
$xlApp->ActiveSheet->Cells(1,5)->Value = "Budget";
$xlApp->ActiveSheet->Cells(1,6)->Value = "Used";
//***********//
$intRows = 2;
while($objResult = mssql_fetch_array($objQuery))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["CustomerID"];
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["Name"];
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["Email"];
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["CountryCode"];
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["Budget"];
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["Used"];
$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;
}
mssql_close($objConnect);
?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
</body>
</html>
ว่าง ๆ เข้าไปอ่านตามที่ผมแนะนำครับ จะได้ไม่งง
|
 |
 |
 |
 |
Date :
2013-03-06 14:34:57 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับพี่ ผมมือใหม่กำลัง งงๆๆ ได้ที่เลย ^^
|
 |
 |
 |
 |
Date :
2013-03-06 14:37:03 |
By :
JonERom3O |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|