I'm trying to create and write a word document within asp.net using:
Does anyone know of a reference for all the objects I can use in word?Code:Word.ApplicationClass WordApp = new Word.ApplicationClass();
DJ
Printable View
I'm trying to create and write a word document within asp.net using:
Does anyone know of a reference for all the objects I can use in word?Code:Word.ApplicationClass WordApp = new Word.ApplicationClass();
DJ
Something like this:
PHP Code:object objFileName = Server.MapPath("MyDocs") + "\\MyDocument.doc";
object missing = System.Reflection.Missing.Value;
Word.ApplicationClass objWord = new Word.ApplicationClass();
Word.Document objDoc = objWord.Documents.Add(ref missing, ref missing, ref missing, ref missing);
objDoc.Activate();
objWord.Selection.TypeText("This is my text");
objWord.Selection.TypeParagraph();
objDoc.SaveAs(ref objFileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
objDoc.Close(ref missing, ref missing, ref missing);
objWord.Application.Quit(ref missing, ref missing, ref missing);
Thanks for that Serge - I'll give it a go.
Do I need any import or using statements?
DJ
You will need to add a reference to Microsoft Word library. Also you will have to change permissions for this library to be used through the web app by using dcomcnfg
You don't happen to know where this Word library is stored? I'm guessing it probably a dll file.
DJ
Actually, its an ActiveX EXE. In your solution explorer right click on the refereces folder and select Add Reference. Then select COM tab and check Microsoft Word 8.0 (or any other version you have installed).
I don't have Visual Studio .NET unfortunately (Billy Gates charges to much for humble me!) - could you let me know the path and name of the file.
Thanks very much for all your help - it's much appreciated!
DJ
Usually it's in:
C:\Program Files\Microsoft Office\Office\WinWord.EXE
Actually, you can't reference an EXE.
The file is an object library:
C:\Program Files\Microsoft Office\Office\MSWord*.olb
where * is 8 for Word97 or 9 for Word 2000
In the end I found a better way - downloading the primary interop assemblies (PIAs) from Microsoft.
Thanks for all your help tho'.
Anyone know of a good online resource for the word document model?
Cheers
DJ
I'll answer my own question - http://msdn.microsoft.com/library/de.../womthquit.asp.
DJ