473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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

Expand|Select|Wrap|Line Numbers
  1. ApplicationClass objWordApp = new ApplicationClass();
  2. Document objWordDoc = new Document();          
  3.  
  4. foreach (string eachfile in lstfile.Items)
  5. {
  6.                 Object nothing = System.Reflection.Missing.Value; 
  7.                 Object fileName = txtFilename.Text.ToString(); 
  8.                 Object notTrue = false;  
  9.                 Object missing = System.Reflection.Missing.Value;
  10.                 objWordDoc = null;
  11.  
  12.                 Object readOnly = false;
  13.                 Object isVisible = false;
  14.  
  15.                 objWordApp.Visible = false;
  16.  
  17.                 objWordDoc = objWordApp.Documents.Open(ref fileName, ref missing,
  18.                       ref readOnly, ref missing, ref missing, ref missing,
  19.                       ref missing, ref missing, ref missing, ref missing,
  20.                       ref missing, ref isVisible, ref missing, ref missing,
  21.                       ref missing, ref missing);
  22.                 objWordDoc.Activate();
  23.                 objWordApp.Visible = false;
  24.  
  25.                 string InDoc = OPagPath + "\\" + eachfile;
  26.                 objWordApp.Selection.InsertFile(PagFpath, ref missing, ref missing, ref missing, ref missing);
  27.  
  28.     //Here I need help to find and replace with particular style
  29. }
  30.  
  31. objWordApp.Quit(ref notTrue, ref missing, ref missing);
  32.  
I need your help/suggestion to find text and replace with its style.
Apr 15 '09 #1
0 1271

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Caversham | last post by:
Is there any macro / other tool - free or commercial - that can split long Word docs into multiple XHTML pages? Any comments on the quality/effectiveness of suitable products also welcomed.
1
by: mickeydisn | last post by:
Sub: C++ Word automation Extract text hello. I want extact text form a word document using a visual c++ programme. I have see a lot of documentation. and my analysis is that I must use a...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
2
by: kids | last post by:
Does anybody know any reason which could cause Ms. word automation to crash? I try to call word automation to open a document and use find and replace function. For some reason it works but I...
4
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
4
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
5
by: Daniel Walzenbach | last post by:
Hi, I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed). The preferable solution would be...
10
by: cj2 | last post by:
I open a word template in VB and add values to the bookmarks then save the document as as pdf. When I then go to close the document it pops up a save as dialog box. It's already saved the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.