Learning & Integrating web technology and code help directory

How to use PHP & Word (Word.Application) - Open Document (Documents.Open)

No comments
How to use PHP & Word (Word.Application) - Open Document (Documents.Open) The Learn / Lutorial / Sctipts php programming how to using  PHP open word document and write text into same document.
ShotDev Focus:
- PHP  & Open word document and write text into same document.

PHP & Open Document (Documents.Open)
Example
php_open_word.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. $wdAlignParagraphCenter = "1";  
  8.   
  9. $Wrd = new COM("Word.Application");  
  10.   
  11. $DocName = "MyDoc/MyWord.doc";  
  12.   
  13. //$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp  
  14.   
  15. $Wrd->Application->Visible = False;  
  16.   
  17. $WrdDoc = $Wrd->Documents->Open(realpath("shotdev.dot"));  
  18.   
  19. $MyRange1 = $WrdDoc->Range();  
  20. $MyRange1->ParagraphFormat->Alignment = $wdAlignParagraphCenter;  
  21. $MyRange1->Font->Name = "Verdana";  
  22. $MyRange1->Font->Size = "30";  
  23. $MyRange1->Font->Bold = True;  
  24. $MyRange1->InsertBefore(chr(13).chr(13)."www.ShotDev.Com".chr(13)."Version 2010".chr(13));  
  25.   
  26. $MyRange1 = $WrdDoc->Paragraphs->Add->Range;  
  27. $MyRange1->InlineShapes->AddPicture(realpath("logo.gif"));  
  28.   
  29. $MyRange1 = $WrdDoc->Paragraphs->Add->Range;  
  30. $MyRange1->ParagraphFormat->Alignment = $wdAlignParagraphCenter;  
  31. $MyRange1->Font->Name = "Verdana";  
  32. $MyRange1->Font->Size = "13";  
  33. $MyRange1->Font->Bold = True;  
  34. $MyRange1->InsertBefore(chr(13).chr(13).chr(13).chr(13)."All Rights Reserved.");  
  35.   
  36. //$WrdDoc->SaveAs($strPath."/".$DocName);  
  37. $WrdDoc->SaveAs(realpath($DocName));  
  38. $Wrd->Application->Quit;  
  39. $Wrd = null;  
  40. ?>  
  41. Word Created <a href="<?=$DocName?>">Click here</a> to Download.  
  42. </body>  
  43. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP & Open Document (Documents.Open)
.

No comments :

Post a Comment