关于在c#中使用word

simon505 2009-12-16 04:32:17
错误 1 命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是缺少程序集引用吗?)
...全文
228 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
simon505 2009-12-18
  • 打赏
  • 举报
回复
错误 1 命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是缺少程序集引用吗?)


什么都重新弄了

还是这样的问题
hujun1024 2009-12-18
  • 打赏
  • 举报
回复
别用这个,安装的Word版本不同,dll就会有所不同
用聚点公司的WebOffice很方便,系统不会崩溃,比DSOFramer好用多了,而且是免费的
Web和WinForm都可以用
http://dianju.com.cn/demo/weboffice/index.asp
qinzhuhua 2009-12-18
  • 打赏
  • 举报
回复
这跟你装office与.net的先后顺序有关
把office安装版插入,点安装,选上支持.net编程的框,把这个装进去
  • 打赏
  • 举报
回复
你的什么没有装完吧?不过有的时候vs也出现了一写比较诡异,甚至说是那种和让人抓狂的错误
woshifou 2009-12-16
  • 打赏
  • 举报
回复
学习。
wuyq11 2009-12-16
  • 打赏
  • 举报
回复
版本是否一致
添加COM组件引用
using System.Runtime.InteropServices
hello_789 2009-12-16
  • 打赏
  • 举报
回复
ding...
RogerXi 2009-12-16
  • 打赏
  • 举报
回复
曾经遇到过相同的问题...
用的是2003的话 应该是2003安装不当 所以导致了这个问题
建议重装一遍office 然后重新获取Office COM 的DLL
simon505 2009-12-16
  • 打赏
  • 举报
回复
到底是怎么回事呢?
simon505 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wartim 的回复:]
看你好像添加的是COM Microsoft Office 11.0

添加引用.Net->Microsoft.Office.Interop.Word

[/Quote]

也添加了的
wartim 2009-12-16
  • 打赏
  • 举报
回复
看你好像添加的是COM Microsoft Office 11.0

添加引用.Net->Microsoft.Office.Interop.Word
simon505 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bersune 的回复:]
添加引用是一个方面,还有你的系统装的是Office那个版本?如果是Office 2003的话,你一定要在安装的时候确定是完全版,不是精简版,其中安装的时候选择自定义安装,一定要勾选上那个.net编程支持的框
[/Quote]

装好了的
我装的2003,也引用了

simon505 2009-12-16
  • 打赏
  • 举报
回复
错误 1 命名空间“Microsoft.Office.Interop”中不存在类型或命名空间名称“word”(是缺少程序集引用吗?)
using word = Microsoft.Office.Interop.word;
改成了
using Microsoft.Office.Interop.word;
bersune 2009-12-16
  • 打赏
  • 举报
回复
添加引用是一个方面,还有你的系统装的是Office那个版本?如果是Office 2003的话,你一定要在安装的时候确定是完全版,不是精简版,其中安装的时候选择自定义安装,一定要勾选上那个.net编程支持的框
simon505 2009-12-16
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.OleDb;
using System.Data.SqlClient;
using word = Microsoft.Office.Interop.word;
using Microsoft.Office.Core;
还是同样的问题
十八道胡同 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 simon505 的回复:]
错误 1 命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是缺少程序集引用吗?)
[/Quote]
记得加引用。Microsoft.Office.Interop.Word
十八道胡同 2009-12-16
  • 打赏
  • 举报
回复
参考
using System;   
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Core;

namespace TestWord
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Word 2007");
Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = true;
Microsoft.Office.Interop.Word._Document oDoc;
object oMissing = System.Reflection.Missing.Value;
object strFileName = "C:\\test.docx";
if (File.Exists((string)strFileName))
File.Delete((string)strFileName);

// Create An New Word
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Paragraphs.Last.Range.Text = "Created An New word !\n\r";
oDoc.SaveAs(ref strFileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Console.WriteLine("Created An New word");

// Open the Word
oDoc = null;
oWord = null;
oWord = new Microsoft.Office.Interop.Word.Application();
oDoc = oWord.Documents.Open(ref strFileName,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oDoc.Paragraphs.Last.Range.Text = "Open The Word !\n\r";
Console.WriteLine("Open The New word");

// Insert a paragraph
Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
oPara1.Range.Text = "Heading 1";
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24; //24 pt spacing after paragraph.
oPara1.Range.InsertParagraphAfter();
Console.WriteLine("Insert a paragraph");

// Close
oDoc.Save();
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Console.WriteLine("Close . Over");
}
}
}


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/LCL_data/archive/2009/07/20/4362961.aspx

111,122

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧