How to use PHP & Word (Word.Application) - Font & Style The Learn / Lutorial / Sctipts php programming how to using PHP Create Word document and add Font & Style
ShotDev Focus:
- PHP & Create Word document and add Font & Style
Example
php_word_style.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <? $wdColorDarkBlue = "&H800000"; $Wrd = new COM("Word.Application"); $Wrd->Application->Visible = False; $Wrd->Documents->Add(); $DocName = "MyDoc/MyWord.doc"; //$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp $Wrd->Selection->PageSetup->LeftMargin = "0.25"; $Wrd->Selection->PageSetup->RightMargin = "0.25"; $Wrd->Selection->PageSetup->TopMargin = "0.25"; $Wrd->Selection->PageSetup->BottomMargin = "0.25"; //*** Font Properties ***// $Wrd->Selection->Font->Name = "Verdana"; $Wrd->Selection->Font->Size = "25"; $Wrd->Selection->Font->Bold = True; $Wrd->Selection->Font->Italic = True; $Wrd->Selection->Font->Color = $wdColorDarkBlue; //$Wrd->Selection->Font->Emboss = True; //$Wrd->Selection->Font->Engrave = True; //$Wrd->Selection->Font->Kerning = True; //$Wrd->Selection->Font->Shadow = True; //$Wrd->Selection->Font->StrikeThrough = True; //$Wrd->Selection->Font->Subscript = True; //$Wrd->Selection->Font->Superscript = True; $Wrd->Selection->TypeText("Welcome To www.ShotDev.Com"); //$Wrd->ActiveDocument->SaveAs($strPath."/".$DocName); $Wrd->ActiveDocument->SaveAs(realpath($DocName)); $Wrd->Application->Quit; $Wrd = null; /* // *** Font Color *** $wdColorAqua = "&HCCCC33"; $wdColorAutomatic = "&HFF000000"; $wdColorBlack = "&H0"; $wdColorBlue = "&HFF0000"; $wdColorBlueGray = "&H996666"; $wdColorBrightGreen = "&HFF00"; $wdColorBrown = "&H3399"; $wdColorDarkBlue = "&H800000"; $wdColorDarkGreen = "&H3300"; $wdColorDarkRed = "&H80"; $wdColorDarkTeal = "&H663300"; $wdColorDarkYellow = "&H8080"; $wdColorGold = "&HCCFF"; $wdColorGray05 = "&HF3F3F3"; $wdColorGray10 = "&HE6E6E6"; $wdColorGray125 = "&HE0E0E0"; $wdColorGray15 = "&HD9D9D9"; $wdColorGray20 = "&HCCCCCC"; $wdColorGray25 = "&HC0C0C0"; $wdColorGray30 = "&HB3B3B3"; $wdColorGray35 = "&HA6A6A6"; $wdColorGray375 = "&HA0A0A0"; $wdColorGray40 = "&H999999"; $wdColorGray45 = "&H8C8C8C"; $wdColorGray50 = "&H808080"; $wdColorGray55 = "&H737373"; $wdColorGray60 = "&H666666"; $wdColorGray625 = "&H606060"; $wdColorGray65 = "&H595959"; $wdColorGray70 = "&H4C4C4C"; $wdColorGray75 = "&H404040"; $wdColorGray80 = "&H333333"; $wdColorGray85 = "&H262626"; $wdColorGray875 = "&H202020"; $wdColorGray90 = "&H191919"; $wdColorGray95 = "&HC0C0C"; $wdColorGreen = "&H8000"; $wdColorIndigo = "&H993333"; $wdColorLavender = "&HFF99CC"; $wdColorLightBlue = "&HFF6633"; $wdColorLightGreen = "&HCCFFCC"; $wdColorLightOrange = "&H99FF"; $wdColorLightTurquoise = "&HFFFFCC"; $wdColorLightYellow = "&H99FFFF"; $wdColorLime = "&HCC99"; $wdColorOliveGreen = "&H3333"; $wdColorOrange = "&H66FF"; $wdColorPaleBlue = "&HFFCC99"; $wdColorPink = "&HFF00FF"; $wdColorPlum = "&H663399"; $wdColorRed = "&HFF"; $wdColorRose = "&HCC99FF"; $wdColorSeaGreen = "&H669933"; $wdColorSkyBlue = "&HFFCC00"; $wdColorTan = "&H99CCFF"; $wdColorTeal = "&H808000"; $wdColorTurquoise = "&HFFFF00"; $wdColorViolet = "&H800080"; $wdColorWhite = "&HFFFFFF"; $wdColorYellow = "&HFFFF"; */ ?> 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_style.php
Screenshot