- Joined
- 3/6/10
- Messages
- 1
- Points
- 11
Tysken, if your locale is not English, and especially your Excel's language is different from your Windows, you need to be careful about all operations that require data type conversion either explicitly or implicitly.
Try Andy's example to see whether it works. If not, try the following:
If this works, I will be pretty sure your issue is caused by locale mismatch. The best way is to get a matching Windows and Excel or adjusting your regional settings in Control Panel. Alternatively, search MSDN for suggestions. For example, you may need some code like the following: MyExcelAppInstance = (MsExcel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(MsExcel.Application), MyExcelAppInstance);Code:public object SumOfTwoNumbers(Excel.Range NumberOne) { try { double d = Double.Parse(NumberOne.Text, System.Globalization.CultureInfo.InvariantCulture); // or some variant depending on your locale return d+1; } catch(Exception err_) { return err_.ToString(); } }
Congratulation zhouxing for the diagnosis : I faced the same problem as reported by Tysken, applied the suggestion you made, with a minor change in the code for the conversion of the input which caused an error of syntax :
double d = Convert.ToDouble(NumberOne.Value2);
and received a very long message as error code, with a reference to an old format or invalid library.
The problem seems to arise when an English version of Excel is used with different regional settings. The solutions are described here.
.NET4Office : How VSTO solves the Excel LCID or Locale issue in the June CTP build
Thanks zhouxing.
And obviously thanks to Andy for the tutorial, which is outstanding !!!