藉助Word中的書籤獲取指定文字
阿新 • • 發佈:2019-01-03
//新增引用:Microsoft.Office.Interop.Word.dll Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); object file = @"E:\1.doc"; object nullobj = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); string text = doc.Content.Text; doc.Close(ref nullobj, ref nullobj, ref nullobj); app.Quit(ref nullobj, ref nullobj, ref nullobj); Regex reg = new Regex(@"(?is)(?<=\bstart\b)(?:(?!\bend\b).)*"); foreach (Match m in reg.Matches(text)) Response.Write(m.Value);