C#操作Word期间,明明添加了引用Microsoft Word 11.0 Object Lib rary,解果还是报错了。代码、报错如下,请大神指教
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MSWord = Microsoft.Office.Interop.Word;
using
using System.Reflection;
using System.Diagnostics;
namespace _1113
{
class Program
{
static void Main(string[] args)
{
object path;//文件路径变量
string strContent;//文本内容变量
MSWord.Application wordApp;//word应用程序变量
MSWord.Document wordDoc;//word文档变量
path = @"C:\Users\Administrator\Desktop\MyWord.doc";//路径
wordApp = new MSWord.ApplicationClass();//初始化
//如果已存在,则删除
if (File.Exists((string)path))
{
File.Delete((string)path);
}
//由于使用的是COM库,因此有许多变量需要用Missing.Value代替
Object Nothing = Missing.Value;
wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//WdSaveFormat为文档的保存格式
object format = MSWord.WdSaveFormat.wdFormatDocument;
//将wordDoc文档对象的内容保存为DOC文档
wordDoc.SaveAs(ref path, ref format, 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文档对象
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//关闭wordApp组件对象
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
Console.WriteLine(path + "创建完毕!");
Console.ReadKey();
}
}
}
错误 1 命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”。是否缺少程序集引用? D:\我的文档\Visual Studio 2012\自学C#\1113\1113\Program.cs 6 33 1113