Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 15th, 2009, 01:51 AM
Authorized User
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default C# Word Styling Automation

Dear All,

Using C# and word object model, i am automate the process, where based on the tag name present in the document its corresponding style has to be applied for the paragraph.

For instance:
<H1>This is Heading1
<Para>This is Paragraph sample...

Our task is to find the <H1> tag and replace it with "H1" style for the whole

Below is the code where I can open the document and add the template styles into the current file.

ApplicationClass objWordApp = new ApplicationClass();
Document objWordDoc = new Document();          

foreach (string eachfile in lstfile.Items)
                Object nothing = System.Reflection.Missing.Value; 
                Object fileName = txtFilename.Text.ToString(); 
                Object notTrue = false;  
                Object missing = System.Reflection.Missing.Value;
                objWordDoc = null;

                Object readOnly = false;
                Object isVisible = false;

                objWordApp.Visible = false;

                objWordDoc = objWordApp.Documents.Open(ref fileName, ref 

                      ref readOnly, ref missing, ref missing, ref missing,
                      ref missing, ref missing, ref missing, ref missing,
                      ref missing, ref isVisible, ref missing, ref missing,
                      ref missing, ref missing);
                objWordApp.Visible = false;

                string InDoc = OPagPath + "\\" + eachfile;
                objWordApp.Selection.InsertFile(PagFpath, ref missing, ref missing, ref 

missing, ref missing);

    //Here I need help to find and replace with particular style

objWordApp.Quit(ref notTrue, ref missing, ref missing);
I need your help/suggestion to find text and replace with corresponding style.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Automation TheNoobiest Beginning VB 6 1 November 9th, 2007 03:11 PM
word templates automation narendrapawar Classic ASP Basics 3 September 20th, 2006 04:11 AM
Word Automation in XP bmains ASP.NET 1.0 and 1.1 Professional 0 July 21st, 2004 09:27 AM
Word automation in VB bobshark VB How-To 1 June 13th, 2003 08:16 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.