打开并使用C#在Word文档中查找字符串

时间:2018-11-16 13:52:21

标签: c# asp.net

我可以使用c#打开word文档,但我也希望它在我的字符串匹配的页面上打开。

protected void New_Click(object sender, EventArgs e)
    {

        Word.Application app = new Word.Application();
        app.Visible = true;
        object visible = true;
        object filepath = @"D:\Files\Process\TestingDocument-Latest1.docx";
        object optional = System.Type.Missing;

        Word.Document doc = app.Documents.Open(ref filepath, ref optional, ref
            optional, ref optional, ref optional, ref optional, ref optional, ref
            optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);


        object findText = "\"Quotation Day\" means";
        int docc = doc.Paragraphs.Count;
        Word.Range rng = doc.Paragraphs[docc].Range;
        rng.Find.ClearFormatting();
        rng.Find.Execute(ref findText,
                        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                        Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                        Type.Missing, Type.Missing);




    }

让我知道是否需要其他信息。

0 个答案:

没有答案