INFO: Use an Explicit Locale Identifier (LCID) When Automating Excel to Set Currency Formats

ID: Q246501


The information in this article applies to:
  • Microsoft Excel 2000
  • Microsoft Visual C++, 32-bit Professional Edition, versions 5.0, 6.0
  • The Microsoft Foundation Classes (MFC)


SUMMARY

When setting the currency format for an Excel range from an out-of-process Automation client, it is necessary to specify an explicit Locale ID (LCID) if the function should operate using a locale different from the operating system.


MORE INFORMATION

If you Automate Excel from a remote client using Visual C++, you need to be sure that the LCID for the call is specifically known by Excel.

Most Excel functions take an LCID parameter when early binding. If late binding, the LCID passed to IDispatch::Invoke is used as the LCID parameter for the function being called. If you do not explicitly set the LCID to a valid value, Excel assumes the system default.

For example, if you are developing on a system with an English (United States) operating system and you want the Excel currency setting to show DM for German currency, but you ignore the Locale ID, then Excel formats the result with the dollar sign ($) instead of the German currency (DM). Excel does this even if German has been set under the Regional Settings in Control Panel. This is because an LCID of zero is assumed to be the default locale for the system and not a user. Since the system is English (United States), in this example, the currency is displayed in U.S. Dollars.

This can be a problem if the Automation program uses the MFC COleDispatchDriver wrapper classes, because they do not natively support passing a custom LCID. Instead, MFC always passes LOCAL_SYSTEM_DEFAULT as the LCID in its InvokeHelper function. If you need to invoke an Excel Automation function with an explicit LCID, you cannot use InvokeHelper function in MFC, and should instead call IDispatch::Invoke directly.

You will find a table of the numeric values for various locale IDs in the Platform SDK on MSDN.

http://msdn.microsoft.com/library
Search for "Language Identifier" (use the quotes), then scroll to select the topic Language Identifiers - International Features (without the quotes.) You can also find information about it in the WINNT.H, the OLENLS.H and/or the WINNLS.H files.

Additional query words:

Keywords : kbAutomation kbExcel kbMFC kbGrpDSO kbDSupport
Version : WINDOWS:2000; winnt:5.0,6.0
Platform : WINDOWS winnt
Issue type : kbinfo


Last Reviewed: December 22, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.