Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1171

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
<cfset filename="C:\dotNet\demo.doc">
<cfif fileexists(filename)>
<cffile action="delete" file="#filename#">
</cfif>
<cfobject type=".NET" assembly="C:\dotNetApp\WordApp.dll,C:\dotNet\Interop.Office.dll"
name="wordCreator" class="WordApp.WordCreator">
<cfset wordCreator.init("#filename#")>
<cfdump label="WordCreator Class Dump" var="#wordCreator#">
<cfset someText = "ColdFusion created this sample document using Windows .NET class methods.
The text is long enough to appear in the Word file on multiple lines.">
<cfloop from=1 to=5 index =i>
<cfset wordCreator.addText(someText)>
<cfset wordCreator.newParagraph()>
<cfset wordCreator.newParagraph()>
<cfset wordCreator.addText("Starting a new paragraph. It starts a
a new line.")>
<cfset wordCreator.newParagraph()>
<cfset wordCreator.newParagraph()>
</cfloop>
<cfset wordCreator.save()>
The C# source for the WordCreator class is as follows:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
// The commented-out lines could be needed on some systems in place of,
// or in addition to, the line that follows them.
// using Microsoft.Office.Core;
// using Word;
// using Microsoft.Office;
// using Microsoft.Office.Interop;
using Microsoft.Office.Interop.Word;
namespace WordApp {
public class WordCreator {
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
object docType = 0;
object newTemplate = false;
object template = "normal.dot";
object format = WdSaveFormat.wdFormatDocument;
ApplicationClass app = new ApplicationClass();
private object fileName;
private Document doc;
private bool isNewDoc = false;
public WordCreator(String fileName) {
this.fileName = fileName;
app.Visible = true;
if (File.Exists(fileName))
doc = app.Documents.Open(ref this.fileName, ref missing, ref
readOnly, ref missing, ref missing, ref missing, ref missing,
Last updated 1/20/2012
1166

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents