web 2.0

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

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


<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
$wdAlignParagraphCenter = "1";

$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->Open(realpath("shotdev.dot"));

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

$MyRange1 = $WrdDoc->Paragraphs->Add->Range;
$MyRange1->InlineShapes->AddPicture(realpath("logo.gif"));

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

//$WrdDoc->SaveAs($strPath."/".$DocName);
$WrdDoc->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_open_word.php

Screenshot

PHP & Open Document (Documents.Open)
.
.
.

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.