C#怎么操作Richtextbox显示Word文档
2个回答
展开全部
将Word文档嵌入到WinForm窗体显示Word文档内容
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog P_GetFile = new OpenFileDialog();//创建打开文件对话框对象
DialogResult P_dr = P_GetFile.ShowDialog();//显示打开文件对话框
if (P_dr == DialogResult.OK)//是否点击确定
{
WebBrowser.Navigate(P_GetFile.FileName);//打开Word文档并显示
}
}
//在Word文档中插入图片
private void btn_New_Click(object sender, EventArgs e)
{
btn_New.Enabled = false;//停用新建按钮
ThreadPool.QueueUserWorkItem(//使用线程池
(P_temp) =>//使用lambda表达式
{
G_wa = new Word.Application();//创建Word应用程序对象
Word.Document P_wd = G_wa.Documents.Add(//建立新文档
ref G_missing, ref G_missing, ref G_missing, ref G_missing);
Word.Range P_Range = P_wd.Paragraphs[1].Range;//得到段落范围
object P_Ranges = P_Range;//创建ojbect对象
P_wd.InlineShapes.AddPicture(//向文档中插入图片
G_OpenFileDialog.FileName, ref G_missing, ref G_missing, ref P_Ranges);
G_str_path = string.Format(//计算文件保存路径
@"{0}\{1}", G_FolderBrowserDialog.SelectedPath,
DateTime.Now.ToString("yyyy年M月d日h时s分m秒fff毫秒") + ".doc");
P_wd.SaveAs(//保存Word文件
ref G_str_path,
ref G_missing, ref G_missing, ref G_missing, ref G_missing,
ref G_missing, ref G_missing, ref G_missing, ref G_missing,
ref G_missing, ref G_missing, ref G_missing, ref G_missing,
ref G_missing, ref G_missing, ref G_missing);
((Word._Application)G_wa.Application).Quit(//退出应用程序
ref G_missing, ref G_missing, ref G_missing);
this.Invoke(//开始执行窗体线程
(MethodInvoker)(() =>//使用lambda表达式
{
btn_Display.Enabled = true;//启用显示按钮
MessageBox.Show("成功创建Word文档!", "提示!");
}));
});
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog P_GetFile = new OpenFileDialog();//创建打开文件对话框对象
DialogResult P_dr = P_GetFile.ShowDialog();//显示打开文件对话框
if (P_dr == DialogResult.OK)//是否点击确定
{
WebBrowser.Navigate(P_GetFile.FileName);//打开Word文档并显示
}
}
//在Word文档中插入图片
private void btn_New_Click(object sender, EventArgs e)
{
btn_New.Enabled = false;//停用新建按钮
ThreadPool.QueueUserWorkItem(//使用线程池
(P_temp) =>//使用lambda表达式
{
G_wa = new Word.Application();//创建Word应用程序对象
Word.Document P_wd = G_wa.Documents.Add(//建立新文档
ref G_missing, ref G_missing, ref G_missing, ref G_missing);
Word.Range P_Range = P_wd.Paragraphs[1].Range;//得到段落范围
object P_Ranges = P_Range;//创建ojbect对象
P_wd.InlineShapes.AddPicture(//向文档中插入图片
G_OpenFileDialog.FileName, ref G_missing, ref G_missing, ref P_Ranges);
G_str_path = string.Format(//计算文件保存路径
@"{0}\{1}", G_FolderBrowserDialog.SelectedPath,
DateTime.Now.ToString("yyyy年M月d日h时s分m秒fff毫秒") + ".doc");
P_wd.SaveAs(//保存Word文件
ref G_str_path,
ref G_missing, ref G_missing, ref G_missing, ref G_missing,
ref G_missing, ref G_missing, ref G_missing, ref G_missing,
ref G_missing, ref G_missing, ref G_missing, ref G_missing,
ref G_missing, ref G_missing, ref G_missing);
((Word._Application)G_wa.Application).Quit(//退出应用程序
ref G_missing, ref G_missing, ref G_missing);
this.Invoke(//开始执行窗体线程
(MethodInvoker)(() =>//使用lambda表达式
{
btn_Display.Enabled = true;//启用显示按钮
MessageBox.Show("成功创建Word文档!", "提示!");
}));
});
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |