|
 |
|
อยาก Add Hyper Link ตอนสร้าง Excel อ่ะครับ มี Code ด้านในอ่ะครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title>
</head>
<body>
<?
//*** 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();
$xlSheet1 = $xlBook->Worksheets(1);
$xlApp->Application->Visible = False;
//*** Create Sheet 1 ***//
$xlBook->Worksheets(1)->Name = "My Sheet1";
$xlBook->Worksheets(1)->Select;
//*** Width & Height (A1:A1) ***//
$xlApp->ActiveSheet->Range("A1:A1")->ColumnWidth = 40.0;
$xlApp->ActiveSheet->Range("A1:A1")->RowHeight = 25.0;
//*** Write text to Row 1 Column 1 ***//
$xlApp->ActiveSheet->Cells(1,1)->Value = "ThaiCreate.Com ";
$xlApp->ActiveSheet->Cells(1,1)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(1,1)->Font->Bold = True;
$xlApp->ActiveSheet->Cells(1,1)->VerticalAlignment = -4108; //*** Center Rows ***//
$xlApp->ActiveSheet->Cells(1,1)->HorizontalAlignment = -4108; //*** Center Column ***//
$xlApp->ActiveSheet->Cells(1,1)->Font->Size = 12;
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram ";
$xlApp->ActiveSheet->Cells(1,2)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(1,2)->Font->Size = 20;
//*** Width & Height (A2:A2) ***//
$xlApp->ActiveSheet->Range("A2:A2")->BORDERS->Weight = 1; //*** Border ***//
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells(2,1)->Value = "I Love ThaiCreate.Com ";
$xlApp->ActiveSheet->Cells(2,1)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(2,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(2,1)->HorizontalAlignment = 4;
//*** Width & Height (A3:D3) ***//
$xlApp->ActiveSheet->Range("A3:D3")->BORDERS->Color = 44; //*** Border Color ***//
$xlApp->ActiveSheet->Range("A3:D3")->BORDERS->Weight = 1; //*** Border ***//
$xlApp->ActiveSheet->Range("A3:D3")->MergeCells = True; //*** Merge Cells ***//
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells(3,1)->Value = "I Love My Live";
$xlApp->ActiveSheet->Cells(3,1)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(3,1)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(3,1)->HorizontalAlignment = -4108;
$xlApp->ActiveSheet->Cells(3,1)->Interior->ColorIndex = 44; //*** Background Color ***//
//*** Write text to Row 4 Column 5 ***//
$xlApp->ActiveSheet->Cells(4,5)->Value = "My Live";
$xlApp->ActiveSheet->Cells(4,5)->Font->Name = "Tahoma";
$xlApp->ActiveSheet->Cells(4,5)->Font->Size = 10;
$xlApp->ActiveSheet->Cells(4,5)->Font->Italic = True;
$xlApp->ActiveSheet->Cells(4,5)->Font->ColorIndex = 4;
$xlApp->ActiveSheet->Cells(4,5)->EntireColumn->AutoFit; //*** AutoFit Column ***//
@unlink($strFileName); //*** Delete old files ***//
$xlBook->SaveAs($strPath."/".$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>
</html>
อยาก Add Hyper Link ตอนสร้าง Excel อ่ะครับ มี Code ด้านในอ่ะครับ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2017-11-02 15:11:17 |
By :
nut_ch31 |
View :
972 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ล่ะจ๊า
$url = "http://www.google.com";
$name = "Hotel A";
//*** Write text to Row 1 Column 2 ***//
$xlApp->ActiveSheet->Cells($x,1)->Value = "=HYPERLINK(".$url.",".$name.")";
|
 |
 |
 |
 |
Date :
2017-11-02 17:18:31 |
By :
nut_ch31 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|