| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2063 人关注过本帖
标题:C#操作Word期间,明明添加了引用Microsoft Word 11.0 Object Lib rary,解果 ...
只看楼主 加入收藏
米粒大小3
Rank: 1
等 级:新手上路
帖 子:40
专家分:7
注 册:2015-10-25
结帖率:66.67%
收藏
 问题点数:0 回复次数:0 
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
搜索更多相关主题的帖子: Word using System 文档 Nothing 
2017-11-13 11:28
快速回复:C#操作Word期间,明明添加了引用Microsoft Word 11.0 Object Lib rary ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022338 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved