Learning & Integrating web technology and code help directory

How to use PHP & Write/Create excel Sheet (Excel.Application)

No comments
How to use PHP & Write/Create excel Sheet (Excel.Application) The Learn / tutorial php programming how to using  PHP write/create excel sheet.
ShotDev Focus:
- PHP  & Write/Create excel sheet.
Example
php_write_excel.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. //*** Get Document Path ***//  
  8. $strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp  
  9.   
  10. //*** Excel Document Root ***//  
  11. $strFileName = "MyXls/MyExcel.xls";  
  12.   
  13. //*** Connect to Excel.Application ***//  
  14. $xlApp = new COM("Excel.Application");  
  15. $xlBook = $xlApp->Workbooks->Add();  
  16. $xlSheet1 = $xlBook->Worksheets(1);  
  17. $xlApp->Application->Visible = False;  
  18.   
  19. //*** Sheet 1 ***//  
  20. $xlSheet1->Name = "My Sheet1";  
  21.   
  22. //*** Write text to Row 1 Column 1 ***//  
  23. $xlApp->ActiveSheet->Cells(1,1)->Value = "ShotDev.Com";  
  24.   
  25. //*** Write text to Row 1 Column 2 ***//  
  26. $xlApp->ActiveSheet->Cells(1,2)->Value = "Mr.Weerachai Nukitram";  
  27.   
  28. @unlink($strFileName); //*** Delete old file ***//  
  29.   
  30. $xlBook->SaveAs($strPath."/".$strFileName); //*** Save to Path ***//  
  31. //$xlBook->SaveAs(realpath($strFileName)); //*** Save to Path ***//  
  32.   
  33. //*** Close & Quit ***//  
  34. $xlApp->Application->Quit();  
  35. $xlApp = null;  
  36. $xlBook = null;  
  37. $xlSheet1 = null;  
  38. ?>  
  39. Excel Created <a href="<?=$strFileName?>">Click here</a> to Download.  
  40. </body>  
  41. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP & Write/Create excel Sheet (Excel.Application)
.

No comments :

Post a Comment