Home » excel » localization – Set function of Excel Cell via Interop – LOCALIZED

localization – Set function of Excel Cell via Interop – LOCALIZED

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want to add an Excel Function to a Cell via C# and Interop (Office 2010).

Let’s take SUM for example.

Using WorksheetFunction ist NOT what I want, because this is a one time function call.
So what I want is

Xl.Range range = SomeWorksheet.Range["A1"];
range.Formula = "=SUM(A2:A5)";

This is fine if you are using an english version of excel but is an error in every other language.

I found this overview but this would mean to handcode the localization. Not so very nice.

What I need is s.th. like

string localizedFunctionName = Xl.Application.GetFuncName(Func.Sum);

Kind Regards
Martin

How to&Answers:

Try the following:

range.FormulaLocal = "=SUM(A2:A5)";

Read more here: http://msdn.microsoft.com/en-us/library/office/aa205983%28v=office.10%29.aspx and this question: VBA: cannot automatically recalculate Excel formula after updating it — needs manual interaction