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
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
$Wrd = new COM("Word.Application");
$Wrd->Application->Visible = False;
$DocName = "MyDoc/MyWord.doc";
//$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$WrdDoc = $Wrd->Documents->Add();
$WTable = $WrdDoc->Tables->Add($Wrd->Selection->Range, 3, 3); // Colums, Rows
$WTable->Cell(1,1)->Range->Font->Name = "Times New Roman";
$WTable->Cell(1,1)->Range->Text = "ShotDev.Com 1";
$WTable->Cell(1,2)->Range->Font->Size = 18;
$WTable->Cell(1,2)->Range->Bold = True;
$WTable->Cell(1,2)->Range->Font->Italic = True;
$WTable->Cell(1,2)->Range->Text = "ShotDev.Com 2";
$WTable->Cell(2,1)->Range->ParagraphFormat->Alignment = 1; // 0= Left, 1=Center, 2=Right
$WTable->Cell(2,1)->Range->Font->Name = "Arial";
$WTable->Cell(2,1)->Range->Font->Size = 12;
$WTable->Cell(2,1)->Range->Bold = False;
$WTable->Cell(2,1)->Range->ParagraphFormat->Alignment = 2;
$WTable->Cell(3,3)->Range->Font->Name = "Times New Roman";
$WTable->Cell(3,3)->Range->Font->Size = 14;
$WTable->Cell(3,3)->Range->Bold = True;
$WTable->Cell(3,3)->Range->Font->Underline = True;
$WTable->Cell(3,3)->Range->ParagraphFormat->Alignment = 0;
$WTable->Cell(3,2)->Range->Text = "ShotDev.Com 3";
//$Wrd->ActiveDocument->SaveAs($strPath."/".$DocName);
$Wrd->ActiveDocument->SaveAs(realpath($DocName));
$Wrd->Application->Quit;
$Wrd = null;
?>
Word Created <a href="<?=$DocName?>">Click here</a> to Download.
</body>
</html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_word_table.php
Screenshot


