Excel.Application.Version raises COM exception with non-English re

T

trochford

I have an Excel COM add-in (non-VSTO) that I am trying to adapt for
international users. To test, I tried changing my regional settings from
English (United States) to German (Germany) through the control panel. This
has the effect of changing the decimal point to a comma and the list
separator to a semicolon, among other things. However, with this setting,
Excel.Application.Version raises a COM exception when I try to access it,
presumably because it can't handle the change in decimal notation (e.g. 11.0
to 11,0 for Excel 2003).

There seem to be other problems with the region setting as well, since other
COM exceptions are also appearing for the first time on other Excel
references. We are still chasing those down.

Does anyone know a way to get around this? We don't have international
versions of the OS or Excel available for testing, so I don't know if those
would have the same problem.

Any help would be very much appreciated.
 
D

David Thielen

THis is a known bug in Excel (the Excel team calls it a feature). You
need to either install the multi-lingual pack or set the locale to
en-us before calling many (not all) Excel APIs.

We use the following class and then do a:
using (new ForceEnUsCulture(true))
{
pair.FullRange.Select();
}


public class ForceEnUsCulture : IDisposable
{
private const int EN_US_LCID = 1033;
private static readonly CultureInfo enUS = new
CultureInfo("en-US");
private readonly CultureInfo origCI;

/// <summary>
/// Create the object. This will change the culture to
en-US if running in Excel.
/// </summary>
/// <param name="isExcel">true if running in
Excel.</param>
public ForceEnUsCulture(bool isExcel)
{
if (isExcel &&
(Thread.CurrentThread.CurrentCulture.LCID != EN_US_LCID))
{
origCI =
Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture =
enUS;
}
}

/// <summary>
/// Reverts the culture back.
/// </summary>
public void Dispose()
{
if (origCI != null)
Thread.CurrentThread.CurrentCulture =
origCI;
}
}


I have an Excel COM add-in (non-VSTO) that I am trying to adapt for
international users. To test, I tried changing my regional settings from
English (United States) to German (Germany) through the control panel. This
has the effect of changing the decimal point to a comma and the list
separator to a semicolon, among other things. However, with this setting,
Excel.Application.Version raises a COM exception when I try to access it,
presumably because it can't handle the change in decimal notation (e.g. 11.0
to 11,0 for Excel 2003).

There seem to be other problems with the region setting as well, since other
COM exceptions are also appearing for the first time on other Excel
references. We are still chasing those down.

Does anyone know a way to get around this? We don't have international
versions of the OS or Excel available for testing, so I don't know if those
would have the same problem.

Any help would be very much appreciated.


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top