|
|
|
สอบถามพี่ๆ หน่อยครับ เรื่อง code Excel Report/Print Format |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620" />
<title>Report Computer</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","mros") or die("Error Connect to Database");
$objDB = mysql_select_db("equipment");
$cs1 = "SET character_set_results=tis620";
mysql_query($cs1) or die('Error query ' . mysql_error());
$cs2 = "SET character_set_client =tis620";
mysql_query($cs2) or die('Error query ' . mysql_error());
$cs3 = "SET character_set_connection =tis620";
mysql_query($cs3) or die('Error query ' . mysql_error());
$strSQL = "SELECT * FROM test";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "equipm/report.xls";
//*** Connect to Excel.Application ***//
$xlApp = new com ("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name ;
$xlBook->Worksheets(1)->Select;
//*** Header ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "ID";
$xlApp->ActiveSheet->Cells(1,2)->Value = "Brand";
$xlApp->ActiveSheet->Cells(1,3)->Value = "Version";
$xlApp->ActiveSheet->Cells(1,4)->Value = "Code";
$xlApp->ActiveSheet->Cells(1,5)->Value = "Asset";
$xlApp->ActiveSheet->Cells(1,6)->Value = "Tenant";
$xlApp->ActiveSheet->Cells(1,7)->Value = "Note";
$xlApp->ActiveSheet->Cells(1,8)->Value = "Object";
$xlApp->ActiveSheet->Cells(1,9)->Value = "Borrow";
$xlApp->ActiveSheet->Cells(1,10)->Value = "Return";
$xlApp->ActiveSheet->Cells(1,11)->Value = "Sum";
$xlApp->ActiveSheet->Cells(1,12)->Value = "Name";
$xlApp->ActiveSheet->Cells(1,13)->Value = "LastName";
$xlApp->ActiveSheet->Cells(1,14)->Value = "ID_Emp";
$xlApp->ActiveSheet->Cells(1,15)->Value = "Unit";
$xlApp->ActiveSheet->Cells(1,16)->Value = "Telephone";
//***********//
$intRows = 2;
while($objResult = mysql_fetch_array($objQuery))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["id"];
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["brand"];
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["version"];
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["code"];
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["asset"];
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["tenant"];
$xlApp->ActiveSheet->Cells($intRows,7)->Value = $objResult["note"];
$xlApp->ActiveSheet->Cells($intRows,8)->Value = $objResult["object"];
$xlApp->ActiveSheet->Cells($intRows,9)->Value = $objResult["borrow"];
$xlApp->ActiveSheet->Cells($intRows,10)->Value = $objResult["ree"];
$xlApp->ActiveSheet->Cells($intRows,11)->Value = $objResult["sum"];
$xlApp->ActiveSheet->Cells($intRows,12)->Value = $objResult["name"];
$xlApp->ActiveSheet->Cells($intRows,13)->Value = $objResult["lastname"];
$xlApp->ActiveSheet->Cells($intRows,14)->Value = $objResult["employee"];
$xlApp->ActiveSheet->Cells($intRows,15)->Value = $objResult["unit"];
$xlApp->ActiveSheet->Cells($intRows,16)->Value = $objResult["tel"];
$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($objConnect);
?>
Excel Created <a href="<?= $strFileName ?>">Click here</a> to Download.
</body>
</html>
สอบถามพี่ๆ หน่อยครับทำไมมันถึง error
$xlBook->Worksheets(1)->Name ;
$xlBook->Worksheets(1)->Select;
line นี้อ่ะครับ มันเกี่ยวกับฐานข้อมูลเรารึเปล่าครับ
line error
Tag : PHP
|
|
|
|
|
|
Date :
2011-02-18 12:16:01 |
By :
illusionsb |
View :
921 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2011-03-09 11:07:37 |
By :
illusionsb |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|