关于RichTextBox 及 RTF格式文件的保存

摘要:
在C#Visual Studio 2005中,RichTextBox以rtf格式保存文件SaveFileDialogsaveFile1=newSaveFileDialog()//初始化SaveFileDialog以指定文件.saveFile1.DefaultExt=“*.rtf”的rtf扩展名;saveFile1.Filter=“RTF文件

C# Visual Studio 2005中RichTextBox保存文件为rtf格式

SaveFileDialog saveFile1 = new SaveFileDialog();
// Initialize the SaveFileDialog to specify the RTF extention for the file.
saveFile1.DefaultExt = "*.rtf";
saveFile1.Filter = "RTF Files|*.rtf";

// Determine whether the user selected a file name from the saveFileDialog.
if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
               saveFile1.FileName.Length > 0)
{
    // Save the contents of the RichTextBox into the file.
            richTextBox1.SaveFile(saveFile1.FileName);


RichTextBox文本保存为WORD格式:

关于RichTextBox 及 RTF格式文件的保存第1张    private void button1_Click(object sender, System.EventArgs e)
关于RichTextBox 及 RTF格式文件的保存第2张        
...{//保存为WORD文件
关于RichTextBox 及 RTF格式文件的保存第3张
            if(this.richTextBox1.Text=="")
关于RichTextBox 及 RTF格式文件的保存第3张                
return;
关于RichTextBox 及 RTF格式文件的保存第3张            
if(this.saveFileDialog1.ShowDialog()==DialogResult.Cancel)
关于RichTextBox 及 RTF格式文件的保存第3张                
return;
关于RichTextBox 及 RTF格式文件的保存第3张            
string FileName=this.saveFileDialog1.FileName;
关于RichTextBox 及 RTF格式文件的保存第3张            
if(FileName.Length<1)
关于RichTextBox 及 RTF格式文件的保存第3张                
return;
关于RichTextBox 及 RTF格式文件的保存第3张            FileName
+=".doc";
关于RichTextBox 及 RTF格式文件的保存第3张            
try
关于RichTextBox 及 RTF格式文件的保存第12张            
...{
关于RichTextBox 及 RTF格式文件的保存第3张                Word.ApplicationClass MyWord
=new Word.ApplicationClass(); 
关于RichTextBox 及 RTF格式文件的保存第3张                Word.Document MyDoc;                
关于RichTextBox 及 RTF格式文件的保存第3张                Object Nothing
=System.Reflection.Missing.Value; 
关于RichTextBox 及 RTF格式文件的保存第3张                MyDoc
=MyWord.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing); 
关于RichTextBox 及 RTF格式文件的保存第3张                MyDoc.Paragraphs.Last.Range.Text
=this.richTextBox1.Text; 
关于RichTextBox 及 RTF格式文件的保存第3张                
object MyFileName=FileName;
关于RichTextBox 及 RTF格式文件的保存第3张                
//将WordDoc文档对象的内容保存为DOC文档 
关于RichTextBox 及 RTF格式文件的保存第3张
//                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); 
关于RichTextBox 及 RTF格式文件的保存第3张                
//关闭WordDoc文档对象 
关于RichTextBox 及 RTF格式文件的保存第3张
                MyDoc.Close(ref Nothing, ref Nothing, ref Nothing); 
关于RichTextBox 及 RTF格式文件的保存第3张                
//关闭WordApp组件对象 
关于RichTextBox 及 RTF格式文件的保存第3张
                MyWord.Quit(ref Nothing, ref Nothing, ref Nothing);         
关于RichTextBox 及 RTF格式文件的保存第3张                MessageBox.Show(
"WORD文件保存成功","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
关于RichTextBox 及 RTF格式文件的保存第26张            }

关于RichTextBox 及 RTF格式文件的保存第3张            
catch(Exception Err)
关于RichTextBox 及 RTF格式文件的保存第12张            
...{
关于RichTextBox 及 RTF格式文件的保存第3张                MessageBox.Show(
"WORD文件保存操作失败!"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
关于RichTextBox 及 RTF格式文件的保存第26张            }

关于RichTextBox 及 RTF格式文件的保存第31张        }

免责声明:文章转载自《关于RichTextBox 及 RTF格式文件的保存》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇MySQL笔记-高可用方案使用json数据动态创建表格2(多次绘制第一次简化 var tr=tbody.insertRow();)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C# 将RTF文档保存到SQLITE当中

表的结构 CREATE TABLE [DATA_TBL]( [ID] VARCHAR PRIMARY KEY, [TITLE] TEXT, [RTF] BINARY, [TAG] TEXT); using System.Data.SQLite; string ConnectionString = "Data Source = test.db; Ve...