gpt4 book ai didi

c# - Word 无法触发事件

转载 作者:太空宇宙 更新时间:2023-11-03 14:45:31 25 4
gpt4 key购买 nike

我使用 Microsoft Office Interop Word 已经有一段时间没有任何问题,但现在突然停止工作了。它现在给我异常消息

Word could not fire the event

我正在运行 Windows 10 专业版的最新更新 - 1809,我还安装了 office 2016 和最新更新。我正在运行 Visual Studio 2017

我使用下面的代码来测试这个问题:

using System;
using Word = Microsoft.Office.Interop.Word;

namespace WordTesting
{
class Program
{
static void Main(string[] args)
{
Word.Application application = new Word.Application();
application.Visible = false;
Word.Document document = null;
try
{
document = application.Documents.Open(@"C:\Users\caspe\Desktop\TEST.docx", Visible: false);
}
catch (Exception e)
{
application.Quit();
Console.WriteLine("Exception: {0}", e.Message);
}
Console.ReadKey();
}
}
}

这是我的引用资料: References

上面的代码抛出一个:

Exception thrown: 'System.Runtime.InteropServices.COMException' in WordTesting.exe

Console.Writeline 是:

Exception: Word could not fire the event

完全异常:

System.Runtime.InteropServices.COMException: 'Word could not fire the event.'

UPDATE

I have just tested my build on another windows 10 machine with build 180 and there it works like a charm

我希望有人能找到解决问题的办法,因为我还没有找到。

最佳答案

好吧,这是一个奇怪的解决方案。但是我在这里找到了last post on this pagehere

所以基本上这是一个区域问题。我的地区是 ENG[DAN],因为丹麦。但是当我将所有内容都更改为 ENG[US] 时,它再次起作用。

我的实现的其他一些部分仍然无法正常工作,但现在这已经足够好了。

关于c# - Word 无法触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54422837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com