在VSTO插件中设置CurrentCulture [英] Setting CurrentCulture in VSTO Addin

查看:106
本文介绍了在VSTO插件中设置CurrentCulture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Excel 2007创建VSTO外接程序.在具有英语(英国)区域设置的开发计算机上,所有程序都能正常工作.但是,某些最终用户将具有其他设置.

I am creating a VSTO addin for Excel 2007. All works fine on my development computer with English(UK) regional settings. However some end users will have other settings.

将信息添加到数据库时,所有方法都工作正常,但是当我尝试用英语(美国)区域设置填充数据表时,它会失败.

All works fine when adding information to the database, however when I try and fill a datatable with English(US) regional settings it fails.

Dim TA As New DB_InquiriesTableAdapters.qry_InquiriesTableAdapter
Dim DB As New DB_Inquiries.qry_InquiriesDataTable
TA.Fill(DB) 'FAILS HERE as date format is incorrect for regional settings

我曾尝试在外接程序启动中设置Thread.CurrentCulture,但这会引发异常,并说:

I have tried setting Thread.CurrentCulture in the addin startup but this throws and exception saying:

不支持MSCORLIB文化

MSCORLIB Culture not supported

有人知道如何解决这个问题吗?

Anyone know how to get around this?

推荐答案

我的原始代码是这样的:

My original code was something like this:

Imports System.Threading
Imports System.Globalization

Public Class MyClass

Public Sub MySub
    Thread.CurrentCulture=New CultureInfo("en-GB")
    Thread.CurrentUICulture=New CultureInfo("en-GB")
    ....
End Sub

End Class

尝试设置当前区域性时会抛出异常.

It would throw an exception when trying to set the current culture.

新代码:

Public Class MyClass

Public Sub MySub
    My.Application.SetCulture("en-GB")
    ....
End Sub

End Class

该应用程序是用VS2013 Professional编写的VSTO Excel插件,该类链接到Winforms表单中托管的WPF UserControl.

The application is a VSTO Excel Addin written in VS2013 Professional and the class is linked to a WPF UserControl hosted in a Winforms Form.

希望这有助于更好地解释答案.

Hope this helps explain the answer a little better.

这篇关于在VSTO插件中设置CurrentCulture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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