Search:

Categories

.Net
ASP
Assembly
C
C++
HTML
Java
JavaScript
MySQL
PAscal
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

US Job listings


create a word document

Your Ad Here

This snippet will show you how to create a word document

<?php
$word = new COM("word.application") or die ("couldnt create an instance of word");
echo "loaded , word version{$word->version}";
//bring word to the front
$word->visible = 1;
//open a word document
$word->Documents->Add();
//add some text to the document
$word->Selection->TypeText("this is some sample text in the document");
//save the document as sampleword.doc
$word->Documents[1]->SaveAs("sampleword.doc");
//close word
$word->Quit();
//free object resources
$word->Release();
$word = null;
?>

Comments

Developers coming from an ASP background may recognise some of the ideas here , for example.

$word = new COM("word.application") is the equivalent of this

Set objword = Server.CreateObject("word.application")

Another tool you can use is Visual Basic if you have this available.

In Visual Basic , you start a Standard executable then goto Project / References , from here you locate the Microsoft Word Library and add it to your project . This now means that you can use the object browser in Visual Basic to find out the properties , methods , classes etc of the object .