Microsoft.Office.Core.FileDialog.Execute()方法在非英语语言环境中抛出ComException [英] Microsoft.Office.Core.FileDialog.Execute() method throw ComException on non English Locale

查看:118
本文介绍了Microsoft.Office.Core.FileDialog.Execute()方法在非英语语言环境中抛出ComException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为当前用户使用英语语言环境时,以下代码可以正常工作。但是当我更改为当前用户的非英语语言环境时,dialog.Execute()会抛出异常。有什么想法吗?

代码:

Microsoft.Office.Core。 FileDialog dialog = this .Application.get_FileDialog(Microsoft.Office.Core。 MsoFileDialogType .msoFileDialogSaveAs);

Microsoft.Office.Core.FileDialog dialog = this.Application.get_FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogSaveAs);

int result = dialog.Show();

int result = dialog.Show();

if (结果!= 0)

if (result != 0)

{

dialog.Execute();

}

异常:

System.Runtime.InteropServices.COMException(0x80004005):错误HRESULT E_FAIL已从调用COM组件返回。在Microsoft。 VisualStudio.Tools.Applications.AddInAdapter.Microsoft.VisualStudio.Tools.Applications.Contract.IEntryPointContract2.ExecuteEntryPoints()
在Microsoft.VisualStudio的Microsoft.VisualStudio.Tools.Office.Internal.AddInHostAdapter.ExecuteEntryPoints()
中。 Tools.Office.Runtime.EntryPointView.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.ExecuteEntryPoints()

System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
   at Microsoft.VisualStudio.Tools.Applications.AddInAdapter.Microsoft.VisualStudio.Tools.Applications.Contract.IEntryPointContract2.ExecuteEntryPoints()
   at Microsoft.VisualStudio.Tools.Office.Internal.AddInHostAdapter.ExecuteEntryPoints()
   at Microsoft.VisualStudio.Tools.Office.Runtime.EntryPointView.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.ExecuteEntryPoints()


谢谢,

Henry

推荐答案

我假设您已经解决了问题鉴于帖子已超过7个月,但我想我会完成这个帖子。

这是Excel中的一个已知问题(版本2002-2007)。您可以通过在调用方法之前将当前线程的Culture设置为en-US(并在之后重置它)或在类型上使用InvokeMember来传递en-US文化来解决此问题。

请参阅< a href ="http://support.microsoft.com/kb/320369"> http://support.microsoft.com/kb/320369

Sven
I assume you've already solved your issue given that the post is over 7 month old, but I thought I would complete the thread.

It's an know issue in Excel (versions 2002-2007). You can work around it by setting the Culture of the Current thread to en-US before calling the method (and reset it afterwards) or by using InvokeMember on the type an pass the en-US culture.

See http://support.microsoft.com/kb/320369

Sven


这篇关于Microsoft.Office.Core.FileDialog.Execute()方法在非英语语言环境中抛出ComException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆