header("Content-Type: application/x-msexcel; name=\"excel_file_name.xls\""); header("Content-Disposition: inline; filename=\"excel_file_name.xls\""); header("Pragma: no-cache"); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoftcom:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<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; //*** Add Sheet 4 ***// $xlBook->Sheets->Add; //*** Sheet Default=3 Add New 1 Sheet=4 ***// //*** Create Sheet 1 ***// $xlBook->Worksheets(1)->Name = "My Sheet1"; $xlBook->Worksheets(1)->Select; //*** Write text to Row 1 Column 1 ***// $xlApp->ActiveSheet->Cells(1,1)->Value = "ThaiCreate.Com 1"; //*** Write text to Row 1 Column 2 ***// $xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram 1"; //*** Create Sheet 2 ***// $xlBook->Worksheets(2)->Name = "My Sheet2"; $xlBook->Worksheets(2)->Select; //*** Write text to Row 1 Column 1 ***// $xlApp->ActiveSheet->Cells(1,1)->Value = "ThaiCreate.Com 2"; //*** Write text to Row 1 Column 2 ***// $xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram 2"; //*** Create Sheet 3 ***// $xlBook->Worksheets(3)->Name = "My Sheet3"; $xlBook->Worksheets(3)->Select; //*** Write text to Row 1 Column 1 ***// $xlApp->ActiveSheet->Cells(1,1)->Value = "ThaiCreate.Com 3"; //*** Write text to Row 1 Column 2 ***// $xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram 3"; //*** Create Sheet 4 ***// $xlBook->Worksheets(4)->Name = "My Sheet4"; $xlBook->Worksheets(4)->Select; //*** Write text to Row 1 Column 1 ***// $xlApp->ActiveSheet->Cells(1,1)->Value = "ThaiCreate.Com 4"; //*** Write text to Row 1 Column 2 ***// $xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram 4"; $xlBook->Worksheets(1)->Select; //*** Focus Sheet 1 ***// @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; ?> Excel Created <a href="<?=$strFileName?>">Click here</a> to Download. </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง