How to simply sned output to a Word Document ?
- Hello all,
I have a very simple question, but I couldn't really find guidance on any of the Websites....
This is about an existing WinForms application, developped in Visual Studio 2008, which produces output to a text file.
What I would like to do is simply change the output to be a Word document that would open upon completion of output.
The purpose of replacing the text document is, of course, to be able to present things differently, using various fonts, and all sorts of Word possibilities.
1) I think I can do it by using Interop, but that is not managed code, is it ?
2) I've tried adding a Word project to my Winforms application, but I couldn't transfer the data into it.
3) What is the right thing to do ?
Thanks
Answers
You need to create a word document file and write text into it using either Open XML or Microsoft Office Word Interop.
You will need to have MS word installed on the machine where the app will run if you want to use Microsoft Office Word Interop.
Interop is a managed wrapper on top of the unmanaged API provided by Word, as of now there is no other way to interact with Word in managed form.
When you say you created a Word project I understand that you Created a Word Document project using Visual studio (A VSTO customization), these customizations run inproc of the office applications and thus you can't interact with them directly.
If you just want to have formatting and coloring, I would recommend creating an html file or may be an XML file and an XSLT file for rendering.
If you want to use any other capabilities of Word then you use either Open XML or Interop based on what else you want to do.
Navneet- Marked As Answer byTim LiMSFT, ModeratorWednesday, November 04, 2009 6:30 AM
- Proposed As Answer byNavneetMSFT, AnswererWednesday, November 04, 2009 1:05 AM
- Hello Sygrien,
Welcome ask questions in this forum!
I think the reply from Navneet is definitely right, and if you wants to get start of combine Word Object Model and a managed project, I suggest you could get help from this step by step tutorial:
http://support.microsoft.com/kb/316383
It shows how to Create a New Word Document in a VB.NET project.
Hope this helps you, looking forward to your comments.
Thanks.
Tim Li
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer byTim LiMSFT, ModeratorThursday, November 05, 2009 2:19 AM
All Replies
You need to create a word document file and write text into it using either Open XML or Microsoft Office Word Interop.
You will need to have MS word installed on the machine where the app will run if you want to use Microsoft Office Word Interop.
Interop is a managed wrapper on top of the unmanaged API provided by Word, as of now there is no other way to interact with Word in managed form.
When you say you created a Word project I understand that you Created a Word Document project using Visual studio (A VSTO customization), these customizations run inproc of the office applications and thus you can't interact with them directly.
If you just want to have formatting and coloring, I would recommend creating an html file or may be an XML file and an XSLT file for rendering.
If you want to use any other capabilities of Word then you use either Open XML or Interop based on what else you want to do.
Navneet- Marked As Answer byTim LiMSFT, ModeratorWednesday, November 04, 2009 6:30 AM
- Proposed As Answer byNavneetMSFT, AnswererWednesday, November 04, 2009 1:05 AM
- Hello Sygrien,
Welcome ask questions in this forum!
I think the reply from Navneet is definitely right, and if you wants to get start of combine Word Object Model and a managed project, I suggest you could get help from this step by step tutorial:
http://support.microsoft.com/kb/316383
It shows how to Create a New Word Document in a VB.NET project.
Hope this helps you, looking forward to your comments.
Thanks.
Tim Li
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer byTim LiMSFT, ModeratorThursday, November 05, 2009 2:19 AM
- Navneet,
Thank you for this great answer ! Precise and synthetic. Right what I was expecting !
Now, I don't know much about XML and XSLT, so I will do this with Interop.
Thanks again
Tim Li,
Thank you very much for this article. Yes, it definitely helps!
Thanks to both of you guys for your quick responses. What a difference this makes !!


