Search code examples
c#excelsystemlocaleadd-in

Running Excel in a different locale/Change system locale settings


I'm trying to find a way to change the locale settings when opening Excel, or changing the entire system locale settings. I know it's bad practice to do this, so I'll just note that this is purely for automated testing reasons. We want to run our Excel add-in simulating multiple different locale settings to make sure it's handling all the functions properly (if there's a better way of doing this than changing settings please let me know!)

I know how to change the CurrentCulture of the thread, but that only seems to apply to our add-in, so functions of Excel called by our add-in run with the system locale settings.

There are 3 ways I've found that I thought might get this working, but one of them seems like an insanely bad idea, and the other two I can't manage to get working:

  • The really bad one was to import a .reg file in to the system registry before opening Excel, but I don't like the idea of this.
  • Another way seems to be to use SetLocaleInfo, imported from kernel32.dll, but for the life of me I can't figure out the parameters to use, or even if this is what I need.
  • The last way was to use Microsofts AppLocale tool, but opening it through that with different language settings didn't seem to achieve what I expected. Actually, it didn't seem to change anything at all from my current system settings!

If anyone can provide any help it would be greatly appreciated, otherwise I guess these are just being left as manual tests!


Solution

  • Here you have a full example of how to call SetLocaleInfo from .Net. I won't copy here for brevity, it's a

    http://took1.googlecode.com/svn-history/r87/trunk/Code/App.Dev/SetLocale.cs