September 29th, 2009, 01:02 PM
Join Date: Sep 2009
Time spent in forums: 22 m 34 sec
Reputation Power: 0
Newbie questions on generating Word document from ColdFusion
I have a couple of questions and would appreciate if someone could respond to them.
The application I am expected to maintain and enhance prints out reports in PDF format which we need to be in MS-Word format. I have looked at the source for the application and see the below lines in one file
<cfdocument format="pdf" filename="#report_filename_format#" orientation="landscape"
Is there a way to do it in the program so that the output is a MS-Word document? I understand the format attribute can take only "PDF" or "flashpaper" as values as per ColdFusion_Documentation
I looked at the example at easycfm which shows how you can generate a Word document using ColdFusion. I am reproducing the example below
<!--- Try to connect to the Word application object --->
<!--- If it exists, connect to it --->
<!--- The object doesn't exist, so create it --->
/* 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 */
/* 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 */
/* Close the document */
/* Quit Word */
The first time I ran it it worked well and a word document called Hello.doc was created. The next time, I changed the text to be printed in the Word document from "Hello World" to "Hello World again" it did not and I got the error message "Error Occurred While Processing Request
The SaveAs method was not found. There are no methods with the specified method name and argument types. Check your function and try again. "
I understand the first time, there was no Word document application object so it was created and the text was written to it properly. The next time, ColdFusion is trying to connect to the Word application object which exists, but somehow it is failing. I changed the name of Word file to be written from Hello.doc to Hello123.doc, but it still did not work. I have permissions to write in the directory where the Word file is being created which is why the example ran fine the first time.
The way I am running this example is typing code in a file called helloworld.cfm which is present in my C:\ColdFusion8\wwwroot\CFIDE\administrator\ directory using Editplus editor, then opening a browser and trying to open a page
1. Is this the proper method?
2. Can someone please clarify where I might be erring in running this example and how can I fix it?
3. Is there an easier way to get the output from ColdFusion in MS-Word format than what I am doing?
Thanks a lot.