|
|
|
Parse error: syntax error, unexpected T_OBJECT_OPERATOR |
|
|
|
|
|
|
|
สวัสดีครับ วันนี้ผมปัญหาครับ คือผมเขียนบน Localhost แล้ว Run มัน Run ได้ปกติแต่พออัฟขึ้น SV. จริง มันฟ้อง
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in C:\AppServ\www\repair\rpexcel.php on line 45
ไม่เข้าใจเหมือนกันครับ แก้ไงบอกหน่อยครับ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", "123");
//$dbname = "Repair2";
//mysql_select_db($dbname) or die("ERROR");
//mysql_query("USE num_new");
//mysql_query("SET NAMES tis620", $conn);
include 'connect.php';
$sql="SELECT
`rp_datajan`.`id`,
`rp_datajan`.`pname`,
`rp_datajan`.`fname`,
`rp_datajan`.`lname`,
`rp_departsub`.`name`,
`rp_datajan`.`phone`,
`rp_datajan`.`id_typebroke`,
`rp_datajan`.`remake`,
`rp_datajan`.`id_status`,
`rp_datajan`.`datejan`,
`rp_datajan`.`nameuserrepair`,
`rp_datajan`.`result`
FROM
`rp_datajan`
Inner Join `rp_departsub` ON `rp_datajan`.`id_departsub` = `rp_departsub`.`id`";
$result = mysql_query($sql);
if($result){
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
//*** Excel Document Root ***//
$strFileName = "MyExcel/MyExcel.xls";
//*** Connect to Excel.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Add();
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "My Job";
$xlBook->Worksheets(1)->Select;
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 5.0;
$xlApp->ActiveSheet->Range("B1:B1")->ColumnWidth = 7.0;
$xlApp->ActiveSheet->Range("C1:C1")->ColumnWidth = 15.0;
$xlApp->ActiveSheet->Range("D1:D1")->ColumnWidth = 15.0;
$xlApp->ActiveSheet->Range("E1:E1")->ColumnWidth = 30.0;
$xlApp->ActiveSheet->Range("F1:F1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("G1:G1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("H1:H1")->ColumnWidth = 50.0;
$xlApp->ActiveSheet->Range("I1:I1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("J1:J1")->ColumnWidth = 10.0;
$xlApp->ActiveSheet->Range("K1:K1")->ColumnWidth = 20.0;
$xlApp->ActiveSheet->Range("L1:L1")->ColumnWidth = 50.0;
//*** Report Title ***//
$xlApp->ActiveSheet->Range("A1:F1")->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Range("A1:F1")->MergeCells = True;
$xlApp->ActiveSheet->Range("A1:F1")->Font->Bold = True;
$xlApp->ActiveSheet->Range("A1:F1")->Font->Size = 20;
$xlApp->ActiveSheet->Range("A1:F1")->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(1,1)->Value = "JOB";
//*** Header ***//
$xlApp->ActiveSheet->Cells(3,1)->Value = "ID";
$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 = "Sex";
$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 = "Name";
$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 = "LastName";
$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 = "Depart Sub";
$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 = "Phone";
$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 = "Item";
$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 = "Trouble";
$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 = "Status";
$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 = "Date";
$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 = "Name Support";
$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 = "solve a problem";
$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;
//***********//
$intRows = 4;
while($objResult = mysql_fetch_array($result))
{
//*** Detail ***//
$xlApp->ActiveSheet->Cells($intRows,1)->Value = $objResult["id"];
$xlApp->ActiveSheet->Cells($intRows,1)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,2)->Value = $objResult["pname"];
$xlApp->ActiveSheet->Cells($intRows,2)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,2)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,3)->Value = $objResult["fname"];
$xlApp->ActiveSheet->Cells($intRows,3)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,3)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->Value = $objResult["lname"];
$xlApp->ActiveSheet->Cells($intRows,4)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,4)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,5)->Value = $objResult["name"];
$xlApp->ActiveSheet->Cells($intRows,5)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,5)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,6)->Value = $objResult["phone"];
$xlApp->ActiveSheet->Cells($intRows,6)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,6)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,7)->Value = $objResult["id_typebroke"];
$xlApp->ActiveSheet->Cells($intRows,7)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,7)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,8)->Value = $objResult["remake"];
$xlApp->ActiveSheet->Cells($intRows,8)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,8)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,9)->Value = $objResult["id_status"];
$xlApp->ActiveSheet->Cells($intRows,9)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,9)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,10)->Value = $objResult["datejan"];
$xlApp->ActiveSheet->Cells($intRows,10)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,10)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,11)->Value = $objResult["nameuserrepair"];
$xlApp->ActiveSheet->Cells($intRows,11)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,11)->BORDERS->Weight = 1;
$xlApp->ActiveSheet->Cells($intRows,12)->Value = $objResult["result"];
$xlApp->ActiveSheet->Cells($intRows,12)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells($intRows,12)->BORDERS->Weight = 1;
$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();
echo "<script>alert('Successful to change to Excel');window.location='MyExcel/MyExcel.xls';</script>";
exit();
?>
</body>
</html>
ขอบคุณครับ
Tag : PHP, CakePHP, Excel (Excel.Application)
|
|
|
|
|
|
Date :
2011-01-31 16:52:22 |
By :
yutthanagorn |
View :
2135 |
Reply :
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดูที่ Line 45 น่ะครับ พวกเครื่องหมาย น่าจะ เปิด ปิด ไม่ครบครับ
|
|
|
|
|
Date :
2011-02-01 08:57:25 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือว่าผมเอา code นี้ run local มันได้ครับ แต่พออัฟขึ้น Server แล้วมันฟ้องตลอดเลย
ผมคิดว่าไม่น่าจะเป็นที่ตัวเครื่องหมาย ขอบคุณครับที่มาตอบให้ผม
|
|
|
|
|
Date :
2011-02-01 10:39:36 |
By :
yutthanagorn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$xlApp = new COM("Excel.Application");
ผมว่าอาจจะเป็นเพราะโฮสใช้ Linux แน่ๆครับ มันไม่มี Excel แต่บนเครื่องเราเป็นวินโดว์และลง Excel เอาไว้ มันเลยรันได้
|
|
|
|
|
Date :
2011-02-01 11:25:56 |
By :
zankumuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าเป็นอย่างนั้นจริง เป็นไปได้ไหมครับว่าเครื่อง Server นั้นไม่ได้ลง office ไว้
|
|
|
|
|
Date :
2011-02-01 13:11:37 |
By :
yutthanagorn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ครับ ส่วนใหญ่เซิฟเวอร์เขาไม่ลงไว้หรอกครับ แต่ทว่า Linux มันไม่มี Excel ด้วยนะซิครับ มีแต่ spreadsheet ถ้าจะใช้ต้องเลือกเซิฟเวอร์ที่เป็น Windows นะครับ
https://www.thaicreate.com/php/php-com-excel.html
|
ประวัติการแก้ไข 2011-02-01 13:16:46
|
|
|
|
Date :
2011-02-01 13:15:41 |
By :
zankumuro |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server linux ต้องเขียนใหม่และครับ หันไปใช้ PHPExcel แทนรันได้ทุก platform
|
|
|
|
|
Date :
2011-02-01 14:02:44 |
By :
PlaKriM |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สรุปว่าปัญหาที่เกิดขึ้นกับผมที่มัน Run บน Server ไม่ผ่านเป็นที่ Excel เหรอครับ หรือง่ายๆเลยคือถ้าจะ run code นี้จะต้องมี excel ในเครื่อง เครื่องนั้น
|
ประวัติการแก้ไข 2011-02-01 14:16:36
|
|
|
|
Date :
2011-02-01 14:14:55 |
By :
yutthanagorn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุรสำหรับทุกๆ คนที่ช่วยครับ แต่มันแก้ไม่ได้อ่ะ T_T
|
|
|
|
|
Date :
2011-02-02 10:02:26 |
By :
yutthanagorn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เปลี่ยนจาก $xlBook->Worksheets(1)->Name = "My Job";
เป็น $xlBook->Worksheets[1]->Name = "My Job";
ให้ใช้ [ ] แทนครับ
|
|
|
|
|
Date :
2011-06-17 09:20:48 |
By :
JacKIE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|