主题:C#请教一个保存为word文档的程序!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
namespace __2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
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;
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, ref Nothing);
MyDoc.Close(ref Nothing, ref Nothing, ref Nothing);
MyDoc.Quit(ref Nothing,ref Nothing,ref Nothing);
MessageBox.Show("你他妈太聪明了,文件保存成功了", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(Exception Err)
{
MessageBox.Show("保存失败了!"+ Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
我就是想把richttext控件里面输入的文字保存为word文档 有错误 怎么回事??
谢谢!
错误 1 命名空间“Microsoft”中不存在类型或命名空间名称“Office”(是缺少程序集引用吗?) D:\Programme\VS\3-2\3-2\Form1.cs 9 24 3-2
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
namespace __2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
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;
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, ref Nothing);
MyDoc.Close(ref Nothing, ref Nothing, ref Nothing);
MyDoc.Quit(ref Nothing,ref Nothing,ref Nothing);
MessageBox.Show("你他妈太聪明了,文件保存成功了", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(Exception Err)
{
MessageBox.Show("保存失败了!"+ Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
我就是想把richttext控件里面输入的文字保存为word文档 有错误 怎么回事??
谢谢!
错误 1 命名空间“Microsoft”中不存在类型或命名空间名称“Office”(是缺少程序集引用吗?) D:\Programme\VS\3-2\3-2\Form1.cs 9 24 3-2