Setting CurrentCulture in VSTO Addin

こ雲淡風輕ζ 提交于 2020-01-25 00:04:17

问题


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

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

MSCORLIB Culture not supported

Anyone know how to get around this?


回答1:


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.

New code:

Public Class MyClass

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

End Class

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.



来源:https://stackoverflow.com/questions/19029153/setting-currentculture-in-vsto-addin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!