Learning & Integrating web technology and code help directory

How to use PHP & Word (Word.Application) - Create/Insert Table (Tables.Add)

1 comment
How to use PHP & Word (Word.Application) - Create/Insert Table (Tables.Add) The Learn / Lutorial / Sctipts php programming how to using  PHP Create Word document and Insert Table (Tables.Add)
ShotDev Focus:
- PHP  & Create Word document and add Insert Table (Tables.Add)
Example
php_word_table.php
  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. $Wrd = new COM("Word.Application");  
  8. $Wrd->Application->Visible = False;  
  9. $DocName = "MyDoc/MyWord.doc";  
  10.   
  11. //$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp  
  12.   
  13. $WrdDoc = $Wrd->Documents->Add();  
  14.   
  15. $WTable = $WrdDoc->Tables->Add($Wrd->Selection->Range, 3, 3); // Colums, Rows  
  16.   
  17. $WTable->Cell(1,1)->Range->Font->Name = "Times New Roman";  
  18. $WTable->Cell(1,1)->Range->Text = "ShotDev.Com 1";  
  19. $WTable->Cell(1,2)->Range->Font->Size = 18;  
  20. $WTable->Cell(1,2)->Range->Bold = True;  
  21. $WTable->Cell(1,2)->Range->Font->Italic = True;  
  22. $WTable->Cell(1,2)->Range->Text = "ShotDev.Com 2";  
  23. $WTable->Cell(2,1)->Range->ParagraphFormat->Alignment = 1; // 0= Left, 1=Center, 2=Right  
  24.   
  25. $WTable->Cell(2,1)->Range->Font->Name = "Arial";  
  26. $WTable->Cell(2,1)->Range->Font->Size = 12;  
  27. $WTable->Cell(2,1)->Range->Bold = False;  
  28. $WTable->Cell(2,1)->Range->ParagraphFormat->Alignment = 2;  
  29.   
  30. $WTable->Cell(3,3)->Range->Font->Name = "Times New Roman";  
  31. $WTable->Cell(3,3)->Range->Font->Size = 14;  
  32. $WTable->Cell(3,3)->Range->Bold = True;  
  33. $WTable->Cell(3,3)->Range->Font->Underline = True;  
  34. $WTable->Cell(3,3)->Range->ParagraphFormat->Alignment = 0;  
  35. $WTable->Cell(3,2)->Range->Text = "ShotDev.Com 3";  
  36.   
  37. //$Wrd->ActiveDocument->SaveAs($strPath."/".$DocName);  
  38. $Wrd->ActiveDocument->SaveAs(realpath($DocName));  
  39. $Wrd->Application->Quit;  
  40. $Wrd = null;  
  41.   
  42. ?>  
  43. Word Created <a href="<?=$DocName?>">Click here</a> to Download.  
  44. </body>  
  45. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP & Create Word Insert Table (Tables.Add)
.

1 comment :