INFO: Use an Explicit Locale Identifier (LCID) When Automating Excel to Set Currency Formats (246501)
The information in this article applies to:
- Microsoft Office Excel 2003
- Microsoft Excel 2002
- Microsoft Excel 2000
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- The Microsoft Foundation Classes (MFC)
This article was previously published under Q246501 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. 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.
Modification Type: | Major | Last Reviewed: | 12/15/2003 |
---|
Keywords: | kbAutomation kbinfo KB246501 |
---|
|