问题
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