Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

New Post: Excel: Names.Add Method

$
0
0
Hi Sebastian,

as mentioned in the issue section some time ago there seems to be an issue with the "names.add" method in the international context.

In VBA I can simply write
Sub example()
    ActiveWorkbook.Names.Add Name:="name1", RefersTo:="=Offset($A$1,0,0,10,1)"
End Sub
In my german Office installation the formula is automatically converted into the german formule, i.e. adding a name "name1" with formula "=BEREICH.VERSCHIEBEN(Tabelle2!$A$1;0;0;10;1)"

This does not work with NetOffice:
[TestMethod]
        public void AddNameEnglish()
        {
            NetOffice.ExcelApi.Application app = new NetOffice.ExcelApi.Application();
            app.Visible = true;
            app.Workbooks.Add();
            app.ActiveWorkbook.Activate();
            app.ActiveWorkbook.Worksheets.Add();

            ((Excel.Worksheet)app.ActiveSheet).Names.Add("name", "=Offset($A$1,0,0,10,1)");

            app.Dispose();            
        }
This throws an exception:
level 1: InnerException {"Ein Aufrufziel hat einen Ausnahmefehler verursacht."} System.Exception {System.Reflection.TargetInvocationException}
level 2: InnerException {"Wir haben ein Problem bei dieser Formel festgestellt. Versuchen Sie, auf der Registerkarte \"Formeln\" auf \"Funktion einfügen\" zu klicken, um das Problem zu beheben, oder klicken Sie auf \"Hilfe\", um weitere Informationen zu häufigen Problemen bei Formeln anzuzeigen.\n\nSie möchten gar keine Formel eingeben?\nWenn das erste Zeichen ein Gleichheitszeichen (=) oder Minuszeichen (-) ist, hält Excel Ihre Eingabe für eine Formel:\n\n• Sie geben \"=1+1\" ein, und die Zelle zeigt: \"2\" an.\n\nZum Vermeiden dieses Problems geben Sie zuerst ein Apostroph ( ' ) ein:\n\n• Sie geben \"'=1+1\" ein, und die Zelle zeigt \"=1+1\" an."} System.Exception {System.Runtime.InteropServices.COMException}

so it looks like NetOffice has a problem in translating the formula properly. I tried the same with the german formula and this works fine:
[TestMethod]
        public void AddNameGerman()
        {
            NetOffice.ExcelApi.Application app = new NetOffice.ExcelApi.Application();
            app.Visible = true;
            app.Workbooks.Add();
            app.ActiveWorkbook.Activate();
            app.ActiveWorkbook.Worksheets.Add();

            ((Excel.Worksheet)app.ActiveSheet).Names.Add("name", "=BEREICH.VERSCHIEBEN($A$1; 0; 0; 10; 1)");

            app.Dispose();
        }
However, I want to use the "auto translation" of the formula as it is available in VBA. The documentation under https://msdn.microsoft.com/en-us/library/office/ff835300.aspx says, that the "RefersTo" parameter should be provided in english ("Describes what the name refers to, in English, using A1-style notation, if the RefersToLocal, RefersToR1C1, and RefersToR1C1Local parameters are not specified.").

So I would highly appreciate if you could look into this. Iam using NetOffice 1.7.3., Win 10 and Excel 2013.

Many thanks and have a nice weekend!

coheedld

Viewing all articles
Browse latest Browse all 1741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>