web 2.0

How to use PHP & Word (Word.Application) - Paragraphs & Range

How to use PHP & Word (Word.Application) - Paragraphs & Range The Learn / Lutorial / Sctipts php programming how to using  PHP Create Word document and add Paragraphs & Range

ShotDev Focus:
- PHP  & Create Word document and add Paragraphs & Range

Example

php_word_paragraphs.php


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
$wdColorDarkRed = "&H80";

$wdAlignParagraphCenter = "1";
$wdAlignParagraphLeft = "0";
$wdParagraph = "4";
$wdHorizontalPositionMargin = "0";
$wdTableLeft = "-999998";
$wdCollapseEnd = "0";

$Wrd = new COM("Word.Application");
$DocName = "MyDoc/MyWord.doc";

//$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp

$Wrd->Application->Visible = False;

$WrdDoc = $Wrd->Documents->Add();

$MyRange1 = $WrdDoc->Paragraphs->Add->Range;
$MyRange1->ParagraphFormat->Alignment = $wdAlignParagraphCenter;
$MyRange1->Font->Name = "Verdana";
$MyRange1->Font->Size = "30";
$MyRange1->Font->Bold = True;
$MyRange1->InsertBefore("www.ShotDev.Com".chr(13)."Version 2010");

$MyRange2 = $WrdDoc->Paragraphs->Add->Range;
$MyRange2->ParagraphFormat->Alignment = $wdAlignParagraphCenter;
$MyRange2->Font->Name = "Verdana";
$MyRange2->Font->Size = "15";
$MyRange2->Font->Bold = True;
$MyRange2->InsertBefore(chr(13).chr(13)."PHP,ASP and ASP.NET Tutorial");

$MyRange3 = $WrdDoc->Paragraphs->Add->Range;
$MyRange3->ParagraphFormat->Alignment = $wdAlignParagraphCenter;
$MyRange3->Font->Name = "Verdana";
$MyRange3->Font->Size = "10";
$MyRange3->Font->Bold = True;
$MyRange3->Font->Color = $wdColorDarkRed;
$MyRange3->Underline = True;
$MyRange3->InsertBefore(chr(13).chr(13).chr(13).chr(13)."All Rights Reserved");

//$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_paragraphs.php

Screenshot

PHP & Create Word Paragraphs & Range
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.