Windows Develop Bookmark and Share   
 index > Windows Forms General > Word automation
 

Word automation

Hi there! I need to create somereport generating engine so i decided to create a word template and"on-fly"changea template's values with a right ones. The problem is that I have Microsoft Office 2007 installed on my machine but Iwant to create a "cross-word" application - is there any ways to include an object library into my build? Or can you describe other ways to create such application? Thank you.
nKognito  Tuesday, December 30, 2008 6:07 AM
I depends on how you are accessing the component object model, which is the only way to get access to the automation server.
If you are using inferfaces only, it should not become very complicated.

The files you need are mso.dll and msword.olb. Just try to import a reference to msword.olb, which is always located at the installation directory of MS Office, Visual Studio will do the rest for you. Or you can use tlbimp.exe on both files.

Then try something like the following

privateboolInitWordInstance(refWord.ApplicationappWord)
{
try
{
TypecomType=Type.GetTypeFromProgID("Word.Application");
if(comType==null)returnfalse;
appWord=Activator.CreateInstance(comType)asWord.Application;
returnappWord!=null;
}
catch(System.Reflection.TargetInvocationException)
{
}
catch(System.Runtime.InteropServices.COMException)
{
}
returnfalse;
}


This should not be troblesome, as long as you use common functions only.

regards,
franking


franking  Tuesday, December 30, 2008 5:28 PM

Hi nKognito,

I am not sure whether I have understood your purpose. Here is an topic talking about Word automation using C#. Please look at it. http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx

If it is not what you want, please feel free to tell me.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Friday, January 02, 2009 3:41 AM
I depends on how you are accessing the component object model, which is the only way to get access to the automation server.
If you are using inferfaces only, it should not become very complicated.

The files you need are mso.dll and msword.olb. Just try to import a reference to msword.olb, which is always located at the installation directory of MS Office, Visual Studio will do the rest for you. Or you can use tlbimp.exe on both files.

Then try something like the following

privateboolInitWordInstance(refWord.ApplicationappWord)
{
try
{
TypecomType=Type.GetTypeFromProgID("Word.Application");
if(comType==null)returnfalse;
appWord=Activator.CreateInstance(comType)asWord.Application;
returnappWord!=null;
}
catch(System.Reflection.TargetInvocationException)
{
}
catch(System.Runtime.InteropServices.COMException)
{
}
returnfalse;
}


This should not be troblesome, as long as you use common functions only.

regards,
franking


franking  Tuesday, December 30, 2008 5:28 PM

Hi nKognito,

I am not sure whether I have understood your purpose. Here is an topic talking about Word automation using C#. Please look at it. http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx

If it is not what you want, please feel free to tell me.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Friday, January 02, 2009 3:41 AM

You can use google to search for other answers

Custom Search

More Threads

• Convert graphics format...
• How to Access Controls On Different From
• application resolution independent
• drilling down
• How to add Items to a Specific Group and Column?
• Countdown Timer of 30 seconds.
• Listview Items Checked
• UI testing application
• How to draw a tree graph in vb.net
• How can I capture cursor(C#)