Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q246501

↑ Back to the top


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.

↑ Back to the top


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.

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.

↑ Back to the top


Keywords: KB246501, kbinfo, kbautomation

↑ Back to the top

Article Info
Article ID : 246501
Revision : 6
Created on : 5/13/2007
Published on : 5/13/2007
Exists online : False
Views : 636