2013-02-25 100 views
2

我需要從特定點開始讀取文檔文檔。 該關鍵詞來自下拉組合框。 關鍵字是一樣的東西[等等等等,等等,001]使用c讀取Word文檔#

所以,我需要閱讀僅從關鍵字下一個標題內容...

我用它來閱讀標題號和行線 抽穗NUM notworking

string headNum = objparagraph.Range.ListFormat.ListString; 
string sLine = objparagraph.Range.Text; 
+0

@soner請提供[C#中讀取word文檔]的一些可能solution.ASAP – 2013-02-25 11:19:47

+0

可能的複製(http://stackoverflow.com/questions/5130911/read -word-document-in-c-sharp) – alex 2016-05-06 13:01:06

回答

2
 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; 
     } 
+0

tmpRange.Text-從Word文檔的doc文件部分讀取文本,以便您可以閱讀文本並進行比較 – 2013-02-25 13:36:54

+0

謝謝你真的幫助了我。 @John – 2013-02-26 03:26:46

+0

有一個小小的疑問... StoryRanges獲取每個標題的內容?? – 2013-02-26 06:12:47