How to get text from line number in MS Word

前端 未结 3 1296
迷失自我
迷失自我 2021-01-22 08:00

Is it possible to get text (line or sentence) from a given line number in MS Word using office automation? I mean its ok if I can get either the text in the given line number or

3条回答
  •  孤街浪徒
    2021-01-22 08:29

    Use this if you want to read standard text .txt files Here is something that you can use to read the files with one call

    List strmsWord = 
        new List(File.ReadAllLines(yourFilePath+ YourwordDocName));
    

    if you want to loop thru and see what the items that were returned use something like this

     foreach (string strLines in strmsWord )
     {
       Console.WriteLine(strLines);
     }     
    

    or

    I totally forgot about something Word docs are probably in binary format so look at this and read the contents into a RichTextBox and from there you could either get at the line number you want or load it into a list after words.. this link will show you Reading from a Word Doc if you want to read the XML Formatting of the word Document: here is a good link as to checkout as well ReadXML Format of a Word Document

    This onne is an even easier example reads contents into the ClipBoard Load Word into ClipBoard

提交回复
热议问题