Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a Word Document Using c#

Tags:

c#

ms-word

I need to start reading a word document from a specific point. That key word is taken from a dropdown combo box. The keyword is something like [blah blah, blah, 001]

So, I need to read only the content from that keyword to next heading ...

I used this to read heading numbers and line by line but heading num notworking

string headNum = objparagraph.Range.ListFormat.ListString;
string sLine = objparagraph.Range.Text;
like image 360
Charan Gourishetty Avatar asked Oct 24 '25 20:10

Charan Gourishetty


1 Answers

       Word.Application word = new Word.Application();
       Word.Document doc = new Word.Document();
       object fileName = @"C:\wordFile.docx";
        // Define an object to pass to the API for missing parameters
        object missing = System.Type.Missing;                
        doc = word.Documents.Open(ref fileName,
                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);
        string ReadValue = string.Empty;
            // Activate the document
        doc.Activate();

         foreach (Word.Range tmpRange in doc.StoryRanges)
         {
            ReadValue += tmpRange.Text;
         }