乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > C#怎么操作Richtextbox显示Word文档-aspose.word,aspose中文文档

C#怎么操作Richtextbox显示Word文档-aspose.word,aspose中文文档

作者:乔山办公网日期:

返回目录:word文档


双击"查找下一个按扭"将这段代码拷到上面:
string str1; //存放要查找的文本
str1 = textBox1.Text;
start = Form1.pCurrentWin.richTextBox1.Find(str1, start, RichTextBoxFinds.MatchCase); //查找下一个
if (start == -1){ MessageBox.Show("已查找到文档的结尾e68a84e799bee5baa6e79fa5e98193364", "查找结束对话框", MessageBoxButtons.OK);
start = 0;}else
start = start + str1.Length; Form1.pCurrentWin.richTextBox1.Focus();//Form1是主窗体
然后再设计一个替换窗体.双击"查找下一个"按扭:再将上面那段代码拷到上面.再双击"替换"按扭:将这段代码拷到上面:
string str1, str2;
str1 = textBox1.Text;
str2 = textBox2.Text;
start = Form1.pCurrentWin.richTextBox1.Find(str1, start, RichTextBoxFinds.MatchCase);
if (start == -1){
MessageBox.Show("已替换到文档的结尾", "替换结束对话框", MessageBoxButtons.OK);start = 0; }
else
Form1.pCurrentWin.richTextBox1.Focus();
再双击"全部替换按扭":将这段代码拷上:
string str1, str2;
str1 = textBox1.Text;
str2 = textBox2.Text;
start = 0;
start = Form1.pCurrentWin.richTextBox1.Find(str1, start, RichTextBoxFinds.MatchCase);
while (start != -1){
Form1.pCurrentWin.richTextBox1.SelectedText = str2;
start += str2.Length;
start = Form1.pCurrentWin.richTextBox1.Find(str1, start, RichTextBoxFinds.MatchCase); }
MessageBox.Show("已替换到文档的结尾", "查找结束对话框", MessageBoxButtons.OK);
start = 0;
Form1.pCurrentWin.richTextBox1.Focus();
其余就是取消按扭事件了.我想这不用我写了吧.至于区分大小写,我还没搞定.等我搞定了再告诉你.你先搞定了你得告诉我哦!460316636我的QQ;

将Word文档嵌入到WinForm窗体显示Word文档内容
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog P_GetFile = new OpenFileDialog();//创建打开文件636f7079e79fa5e98193366对话框对象
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文档!", "提示!");
}));
});
}
参考这篇回答的部试试
http://zhidao.baidu.com/question/258078298.html?oldq=1

只知道保存html 或pdf时能把图片导出来.........
private string ReadWord(string path)
{
Document doc = new Document(path);

using (MemoryStream ms = new MemoryStream())
{
doc.SaveOptions.HtmlExportImagesFolder= "temp/"; //debug下建个temp目录用zd于存图片。
doc.Save(ms, SaveFormat.Html);
string text = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
return text;
}
}

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网