|
|
|
report excel ไม่ขึ้นครับ ช่วยดูให้ผมที ผมรันแล้วมันไม่ขึ้นอะไรเลยอ่ะครับ |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost", "root", "1234");
mysql_query("SET NAMES tis620", $conn);
mysql_query("USE num_new");
$sql = "SELECT * FROM student";
$result = mysql_query($sql);
if($result){
//*** 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 Student";
$xlBook->Worksheets(1)->Select;
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("G1:G1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("H1:H1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("I1:I1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("J1:J1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("K1:K1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("L1:L1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("M1:M1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("N1:N1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("O1:O1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("P1:P1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("Q1:Q1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("R1:R1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("S1:S1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("T1:T1")->ColumnWidth = 20.0;
//*** Report Title ***//
$xlApp->ActiveSheet->Range("F1:J1")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("F1:J1")->MergeCells = True;
$xlApp->ActiveSheet->Range("F1:J1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("F1:J1")->Font->Size = 20;
$xlApp->ActiveSheet->Range("F1:J1")->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(1,1)->Value = "ภูมิลำเนาทหาร";
$xlApp->ActiveSheet->Range("M1:Q1")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("M1:Q1")->MergeCells = True;
$xlApp->ActiveSheet->Range("M1:Q1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("M1:Q1")->Font->Size = 20;
$xlApp->ActiveSheet->Range("M1:Q1")->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(1,1)->Value = "ภูมิลำเนาปัจจุบัน";
//*** Header ***//
$xlApp->ActiveSheet->Cells(3,1)->Value = "ลำดับที่";
$xlApp->ActiveSheet->Cells(3,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,1)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,2)->Value = "รหัสนักศึกษา";
$xlApp->ActiveSheet->Cells(3,2)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,2)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,2)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,3)->Value = "ชื่อ-นามสกุล";
$xlApp->ActiveSheet->Cells(3,3)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,3)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,3)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,4)->Value = "หมายเลขบัตรประชาชน";
$xlApp->ActiveSheet->Cells(3,4)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,4)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,4)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,5)->Value = "พ.ศ.เกิด";
$xlApp->ActiveSheet->Cells(3,5)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,5)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,5)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,6)->Value = "ที่อยู่";
$xlApp->ActiveSheet->Cells(3,6)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,6)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,6)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,7)->Value = "หมู่";
$xlApp->ActiveSheet->Cells(3,7)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,7)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,7)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,7)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,8)->Value = "ตำบล";
$xlApp->ActiveSheet->Cells(3,8)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,8)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,8)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,8)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,9)->Value = "อำเภอ";
$xlApp->ActiveSheet->Cells(3,9)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,9)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,9)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,9)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,10)->Value = "จังหวัด";
$xlApp->ActiveSheet->Cells(3,10)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,10)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,10)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,10)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,11)->Value = "ชื่อบิดา";
$xlApp->ActiveSheet->Cells(3,11)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,11)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,11)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,11)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,12)->Value = "ชื่อมารดา";
$xlApp->ActiveSheet->Cells(3,12)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,12)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,12)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,12)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,13)->Value = "ที่อยู่";
$xlApp->ActiveSheet->Cells(3,13)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,13)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,13)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,13)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,14)->Value = "หมู่";
$xlApp->ActiveSheet->Cells(3,14)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,14)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,14)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,14)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,15)->Value = "ตำบล";
$xlApp->ActiveSheet->Cells(3,15)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,15)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,15)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,15)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,16)->Value = "อำเภอ";
$xlApp->ActiveSheet->Cells(3,16)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,16)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,16)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,16)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,17)->Value = "จังหวัด";
$xlApp->ActiveSheet->Cells(3,17)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,17)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,17)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,17)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,18)->Value = "ใบสำคัญที่/พ.ศ.";
$xlApp->ActiveSheet->Cells(3,18)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,18)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,18)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,18)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,19)->Value = "เบอร์โทรศัพท์";
$xlApp->ActiveSheet->Cells(3,19)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,19)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,19)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,19)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells(3,20)->Value = "ส่งข้อมูลวันที่";
$xlApp->ActiveSheet->Cells(3,20)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(3,20)->VerticalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,20)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,20)->BORDERS->Weight = 1;
//***********//
$intRows = 20;
while($objResult = mysql_fetch_array($objQuery))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["stdnum"];
$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["stdid"];
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["name"];
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["number"];
$xlApp->ActiveSheet->Cells($intRows,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["date"];
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["adr"];
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,6)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,7)->Value = $objResult["type"];
$xlApp->ActiveSheet->Cells($intRows,7)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,7)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,8)->Value = $objResult["place"];
$xlApp->ActiveSheet->Cells($intRows,8)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,8)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,9)->Value = $objResult["district"];
$xlApp->ActiveSheet->Cells($intRows,9)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,9)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,10)->Value = $objResult["provide"];
$xlApp->ActiveSheet->Cells($intRows,10)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,10)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,11)->Value = $objResult["named"];
$xlApp->ActiveSheet->Cells($intRows,11)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,11)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,12)->Value = $objResult["namem"];
$xlApp->ActiveSheet->Cells($intRows,12)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,12)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,13)->Value = $objResult["adr1"];
$xlApp->ActiveSheet->Cells($intRows,13)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,13)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,14)->Value = $objResult["type1"];
$xlApp->ActiveSheet->Cells($intRows,14)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,14)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,15)->Value = $objResult["place1"];
$xlApp->ActiveSheet->Cells($intRows,15)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,15)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,16)->Value = $objResult["district1"];
$xlApp->ActiveSheet->Cells($intRows,16)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,16)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,17)->Value = $objResult["provide1"];
$xlApp->ActiveSheet->Cells($intRows,17)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,17)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,18)->Value = $objResult["numsd9"];
$xlApp->ActiveSheet->Cells($intRows,18)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,18)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,19)->Value = $objResult["tel"];
$xlApp->ActiveSheet->Cells($intRows,19)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,19)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,20)->Value = $objResult["time"];
$xlApp->ActiveSheet->Cells($intRows,20)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,20)->HorizontalAlignment = -4108;
$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($conn);
?>
</body>
</html>
นี่โค๊ดครับ
Tag : PHP, Excel (Excel.Application)
|
|
|
|
|
|
Date :
2014-10-09 17:59:34 |
By :
jakkrapop |
View :
658 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัวนี้จะต้องใช้ Engine ของ Microsoft Office Excel ครับ และอาจจะติดปัญหาเรื่องสิทธิ์ในการใช้งานครับ แนะนำให้ไปใช้ PHPExcel แทนครับ
สร้าง Excel (xls,xlsx) ไฟล์ด้วย PHPExcel และการส่งออก Export
|
|
|
|
|
Date :
2014-10-10 09:33:55 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|