在c#调用word中的问题??

co_fan 2009-01-03 12:17:40
在网上找到别人的调用word的原码,但是我刚着网上的做法做了!也添加了word object libabry 11.0还是报错。
错误如下:Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154.

以下是原码:
private void button1_Click(object sender, EventArgs e)
{
Word.ApplicationClass wd = new Word.ApplicationClass();
object oMissing = System.Reflection.Missing.Value;
wd.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

Word.Document doc = wd.ActiveDocument;
wd.Visible = false;

object extend = null;
object unit = null;
object count = 0;
object character;
extend = Word.WdMovementType.wdExtend;
unit = Word.WdUnits.wdCell;

wd.Selection.Move(ref unit, ref count);
wd.Selection.TypeText("会议通知");
//换行
wd.Selection.MoveRight(ref unit, ref count, ref extend);

count = 2;
character = Word.WdUnits.wdCharacter;
wd.Selection.Move(ref character, ref count);
wd.Selection.TypeText("eeeeeee");
}


...全文
817 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingyun 2009-01-13
  • 打赏
  • 举报
回复
<system.web>

<identity impersonate="true" userName="administrator" password="11111111"/>

</system.web>



检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 8000401a 。

运行dcomcnfg打开组件服务,

依次展开"组件服务"->"计算机"->"我的电脑"->"DCOM配置"

找到"Microsoft Excel应用程序"或"Microsoft Word应用程序",

右键打开属性对话框,点击"标识"选项卡,

点"下列用户",把管理员的用户密码正确填写进去...

点击"安全"选项卡,

依次把"启动和激活权限","访问权限","配置权限",都选择为自定义,
xingyun 2009-01-13
  • 打赏
  • 举报
回复
OLE错误码0X80040154:Class not registered
coclass Application 的 uuid(000209FF-0000-0000-C000-000000000046)

可能word的注册键出了问题,建议重装word
co_fan 2009-01-03
  • 打赏
  • 举报
回复
这个也没有给出具体解决办法,从网上查资料看问题好像是word使用权的问题!
春天的气息 2009-01-03
  • 打赏
  • 举报
回复

private void button1_Click(object sender, EventArgs e)
{
Word.ApplicationClass wd = new Word.ApplicationClass();
object oMissing = System.Reflection.Missing.Value;
wd.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

Word.Document doc = wd.ActiveDocument;
wd.Visible = false;

object extend = null;
object unit = null;
object count = 0;
object character;
extend = Word.WdMovementType.wdExtend;
unit = Word.WdUnits.wdCell;

wd.Selection.Move(ref unit, ref count);
wd.Selection.TypeText("会议通知");
//换行
wd.Selection.MoveRight(ref unit, ref count, ref extend);

count = 2;
character = Word.WdUnits.wdCharacter;
wd.Selection.Move(ref character, ref count);
wd.Selection.TypeText("eeeeeee");
}

子夜1978 2009-01-03
  • 打赏
  • 举报
回复
http://download.csdn.net/source/392743,看一下这个老外写的例子,里面有乱码的地方自己改下吧!比较好用的!

111,130

社区成员

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

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

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