Switch to full style
Codes, tips and tricks,discussions and solutions related to C#
Post a reply

C# Word Styling Automation

Wed Apr 15, 2009 11:06 am

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 document.

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

Code:
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

missing,
                      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);
                objWordDoc.Activate();
                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.

Thanks,
Rangesh



Post a reply
  Related Posts  to : C# Word Styling Automation
 Jobs-130747-Automation Tester in Bangalore, Hyderabad     -  
 word counts in php     -  
 Word & ASP.Net ISSUE     -  
 Simple Word Program     -  
 convert word, Excel to PDF     -  
 Change the word spacing in paragraph     -  
 java code to open word doc attached in ms access.db     -