|
 |
|
รบกวนดูExport sql to excel ให้หน่อยครับ code จากโค้ตไม่errorอ่ะครับแต่มันโหลดนานมากเลยครับรอเท่าไรก็ไม่ขึ้นข้อความ |
|
 |
|
|
 |
 |
|
code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>Untitled Document</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("codebook");
$strSQL = "SELECT * FROM student ";
$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/AimDhram.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
$xlSheet1 = $xlBook->Worksheets(1);
$xlApp->Application->Visible = False;
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "KIN -ตี๋ปากคลอง";
$xlBook->Worksheets(1)->Select;
//*** Insert PicturelogoAimDhram (A1) ***//
$xlApp->Range("A1")->Select();
$Pic = $xlApp->ActiveSheet->Pictures->Insert($strPath."/image/logo.jpg");
$Pic->Width = 70;
$Pic->Height = 65;
//*** Insert PictureKinramen (F1) ***//
$xlApp->Range("F1")->Select();
$Pic = $xlApp->ActiveSheet->Pictures->Insert($strPath."/image/logokin.jpg");
$Pic->Width = 42;
$Pic->Height = 30;
//*** Width (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 6.43;
//*** Width (B1:B1) ***//
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 9.14;
//*** Width (C1:C1) ***//
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 38.86;
//*** Width (D1:D1) ***//
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 8.43;
//*** Width (E1:E1) ***//
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 8.43;
//*** Width (F1:F1) ***//
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 21.43;
$xlApp->ActiveSheet->Range("A10:A10")->RowHeight = 3;
//*** Write text to Row 1 Column 3 ***//
$xlApp->ActiveSheet->Cells(1,3)->Value = " 60/6-10 ถนนรองเมือง ซอย 1 แขวงรองเมือง เขตปทุมวัน ";
$xlApp->ActiveSheet->Cells(1,3)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(1,3)->Font->Size = 8;
//*** Write text to Row 2 Column 3 ***//
$xlApp->ActiveSheet->Cells(2,3)->Value = " กรุงเทพฯ 10330 ";
$xlApp->ActiveSheet->Cells(2,3)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(2,3)->Font->Size = 8;
//*** Write text to Row 3 Column 3 ***//
$xlApp->ActiveSheet->Cells(3,3)->Value = " 60/6-10 Rongmuang Road soi 1, Rongmuang, Pathumwan, ";
$xlApp->ActiveSheet->Cells(3,3)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(3,3)->Font->Size = 8;
//*** Write text to Row 4 Column 3 ***//
$xlApp->ActiveSheet->Cells(4,3)->Value = " Bangkok 10330 ";
$xlApp->ActiveSheet->Cells(4,3)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(4,3)->Font->Size = 8;
//*** Write text to Row 5 Column 4 ***//
$xlApp->ActiveSheet->Cells(5,4)->Value = "เลขที่ ";
$xlApp->ActiveSheet->Cells(5,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(5,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(5,4)->HorizontalAlignment = 4;
//*** Write text to Row 6 Column 4 ***//
$xlApp->ActiveSheet->Cells(6,4)->Value = "วันที่ ";
$xlApp->ActiveSheet->Cells(6,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(6,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(6,4)->HorizontalAlignment = 4;
//*** Write text to Row 7 Column 4 ***//
$xlApp->ActiveSheet->Cells(7,4)->Value = "เงื่อนไข ";
$xlApp->ActiveSheet->Cells(7,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(7,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(7,4)->HorizontalAlignment = 4;
//*** Write text to Row 7 Column 5 ***//
$xlApp->ActiveSheet->Cells(7,5)->Value = " เครดิต 30 วัน ";
$xlApp->ActiveSheet->Cells(7,5)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(7,5)->Font->Size = 10;
//*** Write text to Row 8 Column 4 ***//
$xlApp->ActiveSheet->Cells(8,4)->Value = "โทร ";
$xlApp->ActiveSheet->Cells(8,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(8,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(8,4)->HorizontalAlignment = 4;
//*** Write text to Row 8 Column 5 ***//
$xlApp->ActiveSheet->Cells(8,5)->Value = " 02-214-3430, 02-214-3760 ";
$xlApp->ActiveSheet->Cells(8,5)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(8,5)->Font->Size = 10;
//*** Write text to Row 9 Column 4 ***//
$xlApp->ActiveSheet->Cells(9,4)->Value = "แฟกซ์ ";
$xlApp->ActiveSheet->Cells(9,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(9,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(9,4)->HorizontalAlignment = 4;
//*** Write text to Row 9 Column 5 ***//
$xlApp->ActiveSheet->Cells(9,5)->Value = " 02-215-1888 ";
$xlApp->ActiveSheet->Cells(9,5)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(9,5)->Font->Size = 10;
//*** Write text to Row 6 Column 1 ***//
$xlApp->ActiveSheet->Cells(6,1)->Value = " ชื่อผู้ขาย ";
$xlApp->ActiveSheet->Cells(6,1)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(6,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(6,1)->Font->Bold = True;
$xlApp->ActiveSheet->Range("A6:B7")->MergeCells = True; //*** Merge Cells ***//
$xlApp->ActiveSheet->Cells(6,1)->VerticalAlignment = -4108; //*** Center Rows ***//
//*** Write text to Row 6 Column 3 ***//
$xlApp->ActiveSheet->Cells(6,3)->Value = " ร้านตี๋ปากคลอง ";
$xlApp->ActiveSheet->Cells(6,3)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(6,3)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(6,3)->Font->Bold = True;
$xlApp->ActiveSheet->Range("C6:C7")->MergeCells = True; //*** Merge Cells ***//
$xlApp->ActiveSheet->Cells(6,3)->VerticalAlignment = -4108; //*** Center Rows ***//
//*** Write text to Row 8 Column 1 ***//
$xlApp->ActiveSheet->Cells(8,1)->Value = "สถานที่ส่งสินค้า ";
$xlApp->ActiveSheet->Cells(8,1)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(8,1)->Font->Size = 10;
$xlApp->ActiveSheet->Range("A8:B8")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 9 Column 1 ***//
$xlApp->ActiveSheet->Cells(9,1)->Value = "วันที่ส่งสินค้า ";
$xlApp->ActiveSheet->Cells(9,1)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(9,1)->Font->Size = 10;
$xlApp->ActiveSheet->Range("A9:B9")->MergeCells = True; //*** Merge Cells ***//
////////////////////////////////////////////////////////////////*** Header ***////////////////////////////////////////////
//*** Write text to Row 11 Column 1 ***//
$xlApp->ActiveSheet->Cells(11,1)->Value = " ลำดับ ";
$xlApp->ActiveSheet->Cells(11,1)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(11,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(11,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(11,1)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(11,1)->HorizontalAlignment = -4108; //*** Center Rows ***//
//*** Write text to Row 11 Column 2 ***//
$xlApp->ActiveSheet->Cells(11,2)->Value = " รหัสสินค้า ";
$xlApp->ActiveSheet->Cells(11,2)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(11,2)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(11,2)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(11,2)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(11,2)->HorizontalAlignment = -4108; //*** Center Rows ***//
//*** Write text to Row 11 Column 3 ***//
$xlApp->ActiveSheet->Cells(11,3)->Value = " รายการ ";
$xlApp->ActiveSheet->Cells(11,3)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(11,3)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(11,3)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(11,3)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(11,3)->HorizontalAlignment = -4108; //*** Center Rows ***//
//*** Write text to Row 11 Column 4 ***//
$xlApp->ActiveSheet->Cells(11,4)->Value = " จำนวน ";
$xlApp->ActiveSheet->Cells(11,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(11,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(11,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(11,4)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(11,4)->HorizontalAlignment= -4108; //*** Center Rows ***//
//*** Write text to Row 11 Column 5 ***//
$xlApp->ActiveSheet->Cells(11,5)->Value = " หน่วย ";
$xlApp->ActiveSheet->Cells(11,5)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(11,5)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(11,5)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(11,5)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(11,5)->HorizontalAlignment= -4108; //*** Center Rows ***//
//*** Write text to Row 11 Column 6 ***//
$xlApp->ActiveSheet->Cells(11,6)->Value = " หมายเหตุ ";
$xlApp->ActiveSheet->Cells(11,6)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(11,6)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(11,6)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(11,6)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(11,6)->HorizontalAlignment = -4108; //*** Center Rows ***//
////////////////////////////////////////////////////////////////***จบ Header ***////////////////////////////////////////////
$intRows = 12;
while($objResult = mysql_fetch_array($objQuery))
{
///////////////////////////////////////////////////////////////////*** Detail ***///////////////////////////////////////////////////
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["no"];
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["code"];
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["sname"];
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["slast"];
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["class_id"];
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["room_id"];
$intRows++;
}
}
mysql_close($objConnect);
///////////////////////////////////////////////////////////////////*** จบ Detail ***///////////////////////////////////////////////////
//*** Write text to Row 13 Column 1-3 ***//
$xlApp->ActiveSheet->Cells(13,1)->Value = " ( ปริยากร ช้างชัย ) ";
$xlApp->ActiveSheet->Cells(13,1)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(13,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(13,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(13,1)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(13,1)->HorizontalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Range("A13:C13")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 14 Column 1-3 ***//
$xlApp->ActiveSheet->Cells(14,1)->Value = " วันที่ 05/05/2552 ";
$xlApp->ActiveSheet->Cells(14,1)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(14,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(14,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(14,1)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(14,1)->HorizontalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Range("A14:C14")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 15 Column 1-3 ***//
$xlApp->ActiveSheet->Cells(15,1)->Value = " ผู้ตรวจสอบ ";
$xlApp->ActiveSheet->Cells(15,1)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(15,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(15,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(15,1)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(15,1)->HorizontalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Range("A15:C15")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 13 Column 4-6 ***//
$xlApp->ActiveSheet->Cells(13,4)->Value = " ( ปริยากร ช้างชัย ) ";
$xlApp->ActiveSheet->Cells(13,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(13,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(13,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(13,4)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(13,4)->HorizontalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Range("D13:F13")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 14 Column 4-6 ***//
$xlApp->ActiveSheet->Cells(14,4)->Value = " วันที่ 05/05/2552 ";
$xlApp->ActiveSheet->Cells(14,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(14,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(14,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(14,4)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(14,4)->HorizontalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Range("D14:F14")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 15 Column 4-6 ***//
$xlApp->ActiveSheet->Cells(15,4)->Value = " ผู้จัดทำ ";
$xlApp->ActiveSheet->Cells(15,4)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(15,4)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(15,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(15,4)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(15,4)->HorizontalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Range("D15:F15")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 2 Column 6 ***//
$xlApp->ActiveSheet->Cells(2,6)->Value = " PO/ใบสั่งซื้อ ";
$xlApp->ActiveSheet->Cells(2,6)->Font->Name = " Cordia New ";
$xlApp->ActiveSheet->Cells(2,6)->Font->Size = 11;
$xlApp->ActiveSheet->Cells(2,6)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(2,6)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(2,6)->HorizontalAlignment = 4;//*** Center Rows ***//
//*** MergeCell & Borders ***//
$xlApp->ActiveSheet->Range("F1:F3")->BORDERS->Weight = 3; //*** Border ***//
$xlApp->ActiveSheet->Range("A11:A11")->BORDERS->Weight = 2; //*** Border ***//
$xlApp->ActiveSheet->Range("B11:B11")->BORDERS->Weight = 2; //*** Border ***//
$xlApp->ActiveSheet->Range("C11:C11")->BORDERS->Weight = 2; //*** Border ***//
$xlApp->ActiveSheet->Range("D11:D11")->BORDERS->Weight = 2; //*** Border ***//
$xlApp->ActiveSheet->Range("E11:E11")->BORDERS->Weight = 2; //*** Border ***//
$xlApp->ActiveSheet->Range("F11:F11")->BORDERS->Weight = 2; //*** Border ***//
$xlApp->ActiveSheet->Range("F1:F3")->MergeCells = True; //*** Merge Cells ***//
@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;
?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
<body>
</body>
</html>
จากโค้ตไม่errorอ่ะครับแต่มันโหลดนานมากเลยครับรอเท่าไรก็ไม่ขึ้นข้อความให้ดาวโหลดสักทีหรือว่าผมเขียนผิดจะแก้ไขอย่างไงหรอครับ
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-05-06 12:10:33 |
By :
GhostLocal |
View :
2293 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง debug ในแต่ล่ะส่วนครับ โดใช้คำสั่ง exit(); ถ้าตรงไหนช้า แสดงว่าตรงนั้นมีปัญหาครับ
|
 |
 |
 |
 |
Date :
2009-05-06 12:15:42 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับแต่ทำไมมันไม่วนลูปแสดงข้อมูลทั้งหมดที่อยู่ในเทเบิ้ลstudentอ่ะครับ
$intRows = 12;
while($objResult = mysql_fetch_array($objQuery))
{
///////////////////////////////////////////////////////////////////*** Detail ***///////////////////////////////////////////////////
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["no"];
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["code"];
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["sname"];
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["slast"];
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["class_id"];
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["room_id"];
$intRows++;
}
}
mysql_close($objConnect);
|
 |
 |
 |
 |
Date :
2009-05-06 13:33:35 |
By :
GhostLocal |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|