操作Excel的时候出现的问题。
这个问题通常是因为安装了英文版的office,但是操作系统的地区设置成非英文区域。
因此,可以在调用的code出使用下面一段code
using (new ChangeLocaleHelper(”en-us”))
{
// do something
}
class ChangeLocaleHelper : IDisposable
{
private string _localeName;
private string _originalLocale;
public ChangeLocaleHelper(string localeName)
{
this._localeName = localeName;
_originalLocale = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this._localeName);
}
#region IDisposable Members
public void Dispose()
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this._originalLocale);
}
#endregion
}