<html> <head> <title>ThaiCreate.Com PHP(COM) Excel.Application Tutorial</title> </head> <body> <?php //*** Get Document Path ***// $strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp $xlEdgeLeft = 7; $xlEdgeTop = 8; $xlEdgeBottom = 9; $xlEdgeRight = 10; //*** 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; //*** Sheet 1 ***// $xlSheet1->Name = "My Sheet1"; //*** Write text to Row 1 Column 1 ***// $xlApp->ActiveSheet->Cells(1,1)->Value = "ThaiCreate.Com"; //*** Insert Picture (1) ***// $xlApp->Range("B3")->Select(); $xlApp->ActiveSheet->Pictures->Insert($strPath."/thaicreate.jpg")->Select(); //*** Insert Picture (2) ***// $xlApp->Range("I3")->Select(); $Pic = $xlApp->ActiveSheet->Pictures->Insert($strPath."/thaicreate.jpg"); $Pic->Width = 200; $Pic->Height = 200; @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="<?php echo $strFileName?>">Click here</a> to Download. </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท