determine version of office

Add-in Express™ Support Service
That's what is more important than anything else

determine version of office
 
Ming Chao




Posts: 20
Joined: 2019-01-23
Hi

we are currently relied on the version number to determine the version of office in our app. for instance, 15 would translate to 2013; however both excel 2016 and 2019 are having the same version number(16) which seems not the most reliable way do such task. what would be the best way to find out the office version for all version of offices programatically?

thanks,
Posted 23 Jan, 2019 17:47:56 Top
Andrei Smolin


Add-in Express team


Posts: 16600
Joined: 2006-05-11
Hello Ming,

There's no such way as Office 2019 is just a new name for Office 2016; see e.g. https://www.asap-utilities.com/blog/index.php/2018/10/05/application-version-is-the-new-excel-2019-the-same-as-excel-2016/. Microsoft switched to continuous delivery so I won't be surprised if the next Office version will still report the same version number.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Jan, 2019 02:11:13 Top
Ming Chao




Posts: 20
Joined: 2019-01-23
thank you for your reply Andrei.

it is interesting that Microsoft doesn't increment the version number as it did for the older version of offices.
i looked into the excel process, there're some useful information i could use.
Posted 24 Jan, 2019 20:47:02 Top
Andrei Smolin


Add-in Express team


Posts: 16600
Joined: 2006-05-11
Hello Ming,

Could you pleas share this info with forum readers?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jan, 2019 04:15:26 Top
Nicholas Hebb




Posts: 94
Joined: 2008-08-22
I was playing around using reflection to get the version by checking for a new Excel 2019 worksheet function (I tried TEXTJOIN). Unfortunately, I suck at reflection, so all I came up with is this:


    private bool Is2019(Excel.Application app)
    {
        var methods = app.WorksheetFunction
                    .GetType()
                    .GetMethods()
                    .Select(x => x.Name);
        foreach (var method in methods)
        {
            Console.WriteLine(method);
        }
        /*
            Console output (not what I was hoping):
            ToString
            GetLifetimeService
            InitializeLifetimeService
            CreateObjRef
            Equals
            GetHashCode
            GetType
        */
        return methods.Contains("TEXTJOIN", StringComparer.OrdinalIgnoreCase);
    }


Perhaps someone better at reflection could get this to work.
Posted 25 Jan, 2019 06:44:34 Top
Andrei Smolin


Add-in Express team


Posts: 16600
Joined: 2006-05-11
Hello Nicholas,

            Excel.WorksheetFunction wf = ExcelApp.WorksheetFunction;
            object obj = wf.GetType().GetMethod("TextJoin", System.Reflection.BindingFlags.Public);


The result is null (Nothing in VB.NET).

You can invoke that method; you are in Office 2019 if the call doesn't raise an exception. Not really handy.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jan, 2019 08:17:03 Top
Ming Chao




Posts: 20
Joined: 2019-01-23
i was looking at the product attribute in office 2013 environment. turns out Microsoft removed the version and just keep "microsoft office" for both office 2016 and 2019
Posted 25 Jan, 2019 16:33:09 Top
Andrei Smolin


Add-in Express team


Posts: 16600
Joined: 2006-05-11
Thank you, Ming!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Jan, 2019 03:54:35 Top