|
|
|
สอบถามเรื่อง ดึงข้อมูลจากหลายตารางมา query แล้ว export เป็น excel ค่ะ |
|
|
|
|
|
|
|
เอา Query มาดูครับ
|
|
|
|
|
Date :
2013-05-25 10:28:46 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis620" />
<title>Untitled Document</title>
</head>
<body>
<?
$id_brand=$_POST[id_brand];
$objConnect = mysql_connect("localhost","root","admin") or die("Error Connect to Database");
$objDB = mysql_select_db("invoine");
mysql_query("SET NAMES TIS620");
$strSQL3 = "SELECT * FROM no";
$objQuery3 = mysql_query($strSQL3) or die ("Error Query [".$strSQL3."]");
while($objResult3 = mysql_fetch_array($objQuery3))
{
?>
<?
$strSQL5 = "SELECT * FROM brand where id_brand = '$id_brand'";
$objQuery5= mysql_query($strSQL5) or die ("Error Query [".$strSQL5."]");
while($objResult5 = mysql_fetch_array($objQuery5))
{
?>
<?
$strSQL = "select * from customer where id_brand='$id_brand' and id_no='".$objResult3["id_no"]."' order by id_no,date,area";
echo $strSQL;
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["C:/AppServ/www/inv2"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "stockfg.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "Stock FG";
$xlBook->Worksheets(1)->Select;
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 8.0;
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 12.0;
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 13.0;
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 13.0;
//*** Report Title ***//
$xlApp->ActiveSheet->Range("A1:E1")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("A1:E1")->MergeCells = True;
$xlApp->ActiveSheet->Range("A1:E1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("A1:E1")->Font->Size = 18;
$xlApp->ActiveSheet->Range("A1:E1")->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(2,2)->Value = "แบรนด์ $objResult5[name_brand] เบอร์ $objResult3[name_no]";
// head brand
$xlApp->ActiveSheet->Range("A2:E2")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("A2:E2")->MergeCells = True;
$xlApp->ActiveSheet->Range("A2:E2")->Font->Size =14;
$xlApp->ActiveSheet->Range("A2:E2")->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;
//***********//
$intRows = 4;
while($objResult = mysql_fetch_array($objQuery))
{
$date_t = $objResult["date"];
$detail=$objResult["detail"];
if ($detail=='') {
$detail='-';
}
?>
<?
$birthday = $date_t; //???????????????????
$today = date("Y-m-d"); //??????????
$r = mysql_query("SELECT DATEDIFF( '$today', '$date_t' )+1 AS date
FROM customer");
while($row = mysql_fetch_array($r)){
$d_d_back=$row['date'];
}
?>
<?
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["date"];
$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["area"];
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["total"];
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $d_d_back;
$xlApp->ActiveSheet->Cells($intRows,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["status"];
$xlApp->ActiveSheet->Cells($intRows,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["id_no"];
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 1;
$intRows++;
}
@unlink($strFileName); //*** Delete old files ***//
$xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//
//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
}
}
}
mysql_close($objConnect);
?>
Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.
</body>
</html>
|
|
|
|
|
Date :
2013-05-25 10:38:42 |
By :
supattra.s |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|