This example shows how to create a Word document, using "Hello World".

<!--- Try to connect to the Word application object --->
<CFTRY>
    <!--- If it exists, connect to it --->
    <CFOBJECT
        ACTION="">         CLASS="Word.Application"
        NAME="objWord"
        TYPE="COM">
  <CFCATCH>
    <!--- The object doesn't exist, so create it --->
    <CFOBJECT
        ACTION="">         CLASS="Word.Application"
        NAME="objWord"
        TYPE="COM">
  </CFCATCH>
</CFTRY>

<CFSCRIPT>
    /* This will open Word if running locally */
    objWord.Visible = true;

    /* This returns the 'Documents' collection the Word Object */
    objDoc = objWord.Documents;

    /* Create a new document */
    newDoc = objDoc.Add();

    /* Save the document to a location */
    newDoc.SaveAs("D:\template_new.doc");

    /* We specify the range of '0' -- start at the beginning of the document
*/
    docRange = newDoc.Range(0);

    /* Add text to the range */
    docRange.Text = "Hello World!";

    /* Save the changes */
    newDoc.Save();

    /* Close the document */
    newDoc.Close();

    /* Quit Word */
    objWord.Quit();
</CFSCRIPT>

For more tutorials on how to use ColdFusion to interact with COM objects,
visit: http://www.cfcomet.com

--
Peter Tilbrook
ColdFusion Applications Developer
ColdGen Internet Solutions
Manager, ACT and Region ColdFusion Users Group - http://www.actcfug.com
4/73 Tharwa Road
Queanbeyan, NSW, 2620
AUSTRALIA

Telephone: +61-2-6284-2727
Mobile: +61-0439-401-823
E-mail: [EMAIL PROTECTED]

World Wide Web: http:/www.coldgen.com/
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to