//用richTextBox打开带格式的word文档。
//先打开word文档,全选其中的内容并保存的剪切板中,最后在richTextBox中粘贴数据,并关闭文档
public void OpenWord(string fileName)
{
Word.ApplicationClass app = new Word.ApplicationClass();
Word.Document doc = null;
object missing = System.Reflection.Missing.Value;
object File = fileName;
object readOnly = false;
object isVisible = true;
try
{
doc = app.Documents.Open(ref File, 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();//全选word文档中的数据
doc.ActiveWindow.Selection.Copy();//复制数据到剪切板
richTextBox1.Paste();//richTextBox粘贴数据
//richTextBox1.Text = doc.Content.Text;//显示无格式数据
}
finally
{
richTextBox实现带格式word文档的打开、保存、另存为
最新推荐文章于 2022-03-29 17:24:39 发布