How can I use C # to get Excel version include build version and MSO version and check Excel version is 2016 or 2021

Frank Zhu 20 Reputation points
2023-02-13T05:18:48.0066667+00:00

Question1: How can I get Excel Version with C# as same as [File -> Account -> About Excel] as below:
User's image

Question2: How can I determine Excel Version is 2016 or 2021 with C#? I found they are same in registry.

Microsoft 365 and Office | Development | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack J Jun 25,316 Reputation points
    2023-02-13T07:46:08.11+00:00

    @Frank Zhu , Welcome to Microsoft Q&A,

    First, we could get the build version from the Excel.exe in the installed path of computer.

    // If your excel is 32 bit, please use ProgramFiles(x86)
    string path1=Environment.GetEnvironmentVariable("ProgramFiles(x86)")+ "\\Microsoft Office\\Office16\\EXCEL.EXE";
    // If your excel is 64 bit, please use ProgramFiles
    string path2= Environment.GetEnvironmentVariable("ProgramFiles") + "\\Microsoft Office\\Office16\\EXCEL.EXE";
    var file = FileVersionInfo.GetVersionInfo(path1);
    Console.WriteLine(file.FileVersion);
    

    Note: MSO version is not related to excel version, which is related to some office installation. So, there is no need to get it/

    Second, you could try to install nuget-package Microsoft.Office.Interop.Excel and use the following code to check if the Excel Version is 2016 or 2021.

                Excel.Application objApp = new Excel.Application();
                int version=Convert.ToInt32(objApp.Version);
                if(version==16)
                {
                    Console.WriteLine("This is Excel 2016");
                }
                if(version==21)
                {
                    Console.WriteLine("This is Excel 2021");
                }
    
    

    Tested result:

    User's image

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.