引用Microsoft.Office.Interop.Word
用Word元件的Find功能找不到, 只好全文抓出來找
using System;
using Word = Microsoft.Office.Interop.Word;
namespace SaveMail
{
public class WordTool : IDisposable
{
private static readonly Word.Application app = new Word.Application();
private readonly Word.Document doc = null;
#region constructor
public WordTool(string path)
{
doc = app.Documents.Open(path);
}
#endregion
#region property
public string Text
{
get { return (doc != null) ? doc.Content.Text : string.Empty; }
}
public Word.Document Document
{
get { return doc; }
}
#endregion
#region Method
/// <summary>
/// 是否包含
/// </summary>
/// <param name="find"></param>
/// <returns></returns>
public bool Contains(string find)
{
return Text.Contains(find);
}
public void Dispose()
{
if (doc != null)
doc.Close(false);/*
if (app != null)
app.Quit();*/
}
#endregion
}
}
Taiwan is a country. 臺灣是我的國家