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!

有帮助吗?

解决方案 2

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

其他提示

I would suggest creating several users on your computer and adjusting user locale settings accordingly to your test purposes for each user in Control Panel -> Region and Language. This basically allows setting a default language, and currency/number/date/time formats. If this is what you want, you can launch excel using a different user execution context by either runas command, which requires a manual password entering, or in batch mode using psexec tool from SysInternals: http://technet.microsoft.com/en-us/sysinternals/bb897553

Make sure to specifycommand line options that load account's profile. Unfortumnately you can only adjust user locale settings per each user. System locale settings are defined per computer.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top