RichTextBox文本保存为WORD格式
2007-01-24 19:48
561 查看
RichTextBox文本保存为WORD格式:
private void button1_Click(object sender, System.EventArgs e)
...{//保存为WORD文件
if(this.richTextBox1.Text=="")
return;
if(this.saveFileDialog1.ShowDialog()==DialogResult.Cancel)
return;
string FileName=this.saveFileDialog1.FileName;
if(FileName.Length<1)
return;
FileName+=".doc";
try
...{
Word.ApplicationClass MyWord=new Word.ApplicationClass();
Word.Document MyDoc;
Object Nothing=System.Reflection.Missing.Value;
MyDoc=MyWord.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);
MyDoc.Paragraphs.Last.Range.Text=this.richTextBox1.Text;
object MyFileName=FileName;
//将WordDoc文档对象的内容保存为DOC文档
// MyDoc.SaveAs(ref MyFileName,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
//关闭WordDoc文档对象
MyDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//关闭WordApp组件对象
MyWord.Quit(ref Nothing, ref Nothing, ref Nothing);
MessageBox.Show("WORD文件保存成功","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception Err)
...{
MessageBox.Show("WORD文件保存操作失败!"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button1_Click(object sender, System.EventArgs e)
...{//保存为WORD文件
if(this.richTextBox1.Text=="")
return;
if(this.saveFileDialog1.ShowDialog()==DialogResult.Cancel)
return;
string FileName=this.saveFileDialog1.FileName;
if(FileName.Length<1)
return;
FileName+=".doc";
try
...{
Word.ApplicationClass MyWord=new Word.ApplicationClass();
Word.Document MyDoc;
Object Nothing=System.Reflection.Missing.Value;
MyDoc=MyWord.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);
MyDoc.Paragraphs.Last.Range.Text=this.richTextBox1.Text;
object MyFileName=FileName;
//将WordDoc文档对象的内容保存为DOC文档
// MyDoc.SaveAs(ref MyFileName,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
//关闭WordDoc文档对象
MyDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//关闭WordApp组件对象
MyWord.Quit(ref Nothing, ref Nothing, ref Nothing);
MessageBox.Show("WORD文件保存成功","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception Err)
...{
MessageBox.Show("WORD文件保存操作失败!"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
相关文章推荐
- richTextBox实现带格式word文档的打开、保存、另存为.
- winform c# richtextbox保存为txt文本文档
- lumisoft会将eml后缀格式的附件给解析成文本,这里保存成文件
- [Office 2010 易宝典]什么是OpenDocument格式?如何将Word文档保存为该格式?
- 怎样更改Word 2007默认保存格式为doc文档
- 【WPF】如何保存RichTextBox的文本到数据库?以及如何对RichTextBox的Document做绑定?
- 纯文本用textbox,带格式的文本用richtextbox
- python发送图片|文本|word|pdf格式的邮件
- 如何将 Memo中的文本内容保存到当前目录下的 Word 文档中
- 从richTextBox得到字符串并且保存到文本中
- C#中如何保存文本为Word文件或Excel文件 [Z]
- C# Visual Studio 2005中RichTextBox保存文件为rtf格式
- poi读取word简历(伪word格式的doc文件 )提取文本内容报错
- Android文本保存成PDF格式
- #258 – RichTextBox 比TextBox允许显示更丰富的文本格式(RichTextBox Allows Richer Formatting than TextBox)
- vc把文字内容存成word文件和把doc文件保存为txt格式
- 如何在C#下利用RichTextBox打开一个有文字格式和图片的Word文档
- js读取本地磁盘文本文件并保存为JSON数据(有格式的文本)
- C#读取MySql数据库并保存为xml与文本格式
- 把RichTextBox中的文本保存到Sql Server中(C#)