///
/// 添加Word文件,返回文件内容string
///
///
///
public string AddWord(object fileName)
{
string fileContent = "";
Word.ApplicationClass app = new Word.ApplicationClass();
Word.Document doc = null;
object missing = System.Reflection.Missing.Value;
object readOnly = false;
object isVisible = false;
try
{
doc = app.Documents.Open(ref fileName,ref missing,ref readOnly,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref isVisible,ref missing,ref missing,ref missing,ref missing);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
fileContent = data.GetData(DataFormats.Text).ToString();
}
finally
{
if (doc != null)
{
doc.Close(ref missing,ref missing,ref missing);
doc = null;
}
if (doc == null)
{
app.Quit(ref missing,ref missing,ref missing);
app = null;
}
}
return fileContent;
}
转载于:https://www.cnblogs.com/liuzhixian/articles/864793.html