wood burning stoves 2.0*
The moose likes Other Languages and the fly likes How to get current paragraph number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "How to get current paragraph number" Watch "How to get current paragraph number" New topic
Author

How to get current paragraph number

Tamil Selvi
Greenhorn

Joined: Jun 22, 2009
Posts: 6
Dear All,

I am using C#.net with the component of Ms-Word 2003. I am trying to find the Bold word in paragraph-wise (each para have more that one bold words) and get the current paragraph number. So i used below code for searching which has not worked. It do a search on entire word document instead of a specified paragraph.


My Coding Lines:
using msWord = Microsoft.Office.Interop.Word; //Included Ms-Word Namespace Microsoft Office 11.0 Object Library
int paraCnt = 0;
msWord.Application myWrd; //Create an instance for application and document.
msWord.Document myDoc;
object missing = Missing.Value;
object objFile = @"D:\Test\File.doc";

//Open an existing document
msWord._Document myDoc = myWrd.Documents.Open(ref objFile, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
for (int i = 1 ; i <= myDoc.Paragraphs.Count; i ++)
{
Microsoft.Office.Interop.Word.Range myRange = myDoc.Paragraphs[i].Range;
myRange.Select();
object beg = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;
object end = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;
object objTrue = true;
object objFalse = false;
object objWrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindStop;
object objReplace = msWord.WdReplace.wdReplaceNone;
object objFindText = "";
paraCnt += 1; //Incremented when the next paragaph starts
myRange.Find.Format = true;
myRange.Find.Font.Bold = 1;
myRange.Find.Text = "";

myRange.Find.Execute(ref objFindText, ref objFalse, ref objFalse, ref objFalse, ref objFalse, ref objFalse, ref objTrue, ref objWrap, ref objTrue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
while (myRange.Find.Found)
{
MessageBox.Show(myWrd.Selection.Text); //Getting the selected text
MessageBox.Show(paraCnt.ToString()); //Here trying to get a current paragraph number
}
}
myDoc.Close(ref missing, ref missing, ref missing);

Please help me

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get current paragraph number
 
Similar Threads
Writing RTF files from Java Swing DefaultStyledDocuments
insert header and footer with POI HWPF?
How to insert a file in oracle blob object
Editing pdf/word content (text replacement)
MS Word to XML conversion