0

Im working on the Vsto excel add-in and I'm getting the window rect through CreateWindowRect().

I'm running the application with ISO Office2016 Excel and Office365 excel.

The problem is I'm getting a different window rectangle while running the ISO office2016 excel and I have to get the correct window rect while running the application with office365excel.

So I'm planning to adjust the window rectangle while running application with ISO office2016 excel. To check the condition I'm in need to get whether the excel is standalone or office365 excel.

Is there any way to find whether Excel application is Click-to-Run (Online Office 365 installer) or Windows Installer (ISO file or DVD) using c#?

fsbflavio
  • 664
  • 10
  • 22
Sam10
  • 319
  • 2
  • 11
  • Give us more information, please. Do you want to know what is the installed excel version? – fsbflavio Apr 15 '20 at 12:04
  • Hi @fsbflavio, Im working on the Vsto excel addin and Im getting the window rect through CreateWindowRect(). Im running the application with ISO Office2016 Excel and Office365 excel. Im getting different window rectangle while running the ISO office2016 excel and I have getting correct window rect while running the application with office365excel. So Im planning to adjust the window rectangle while running application with ISO office2016 excel. To check the condition Im in need to get whether the excel is standalone or office365 excel. Hope I gave the clear info... – Sam10 Apr 15 '20 at 12:54
  • Have a look at this: https://stackoverflow.com/questions/3266675/how-to-detect-installed-version-of-ms-office/28206722 – fsbflavio Apr 15 '20 at 17:40
  • I edited your question and answered it. The answer solves how to know the Office version, but I believe the best way is to look deep to the CreateWindowRect() logic, and ask another question about it with some code. – fsbflavio Apr 16 '20 at 14:47

1 Answers1

0

A computer can have multiples versions of Office.

But, you can discover if the machine has the Office 365 installed doing something like that:

using Microsoft.Win32;
...

private bool Has365Office()
{
     RegistryView registryView = RegistryView.Registry32;
     string registryKey = "Software\Microsoft\Office\16.0\Common\Licensing\LicensingNext";
     using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, registryView).OpenSubKey(registryKey))
     {
           foreach (string subkeyName in key.GetValueNames())
           {
                if (subkeyName.Contains("o365"))
                    return true;
           }
     }

     return false;
}
...

To know what version is running, or at least will run when the user opens it, you can do something like that:

using Microsoft.Office.Interop;
...

public string GetOfficeVersion()
    {
        string sVersion = string.Empty;
        Microsoft.Office.Interop.Word.Application appVersion = new Microsoft.Office.Interop.Word.Application();
        appVersion.Visible = false;
        switch (appVersion.Version.ToString())
        {
            case "7.0":
                sVersion = "95";
                break;
            case "8.0":
                sVersion = "97";
                break;
            case "9.0":
                sVersion = "2000";
                break;
            case "10.0":
                sVersion = "2002";
                break;
            case "11.0":
                sVersion = "2003";
                break;
            case "12.0":
                sVersion = "2007";
                break;
            case "14.0":
                sVersion = "2010";
                break;
            case "16.0":
                sVersion = "2016 or 2019 or 365";
                break;
            default:
                sVersion = "Too Old!";
                break;
        }
        return sVersion;
    }

You can combine the code above to get what you need. I hope it helps!

both codes were made from this answer: link

fsbflavio
  • 664
  • 10
  • 22
  • Is it possible to find whether the running excel application is standlone or Not?. – Sam10 Apr 16 '20 at 05:10
  • My answer's about discovering what excel version is installed on the machine. Did you saw the link, I 've mentioned? there is an answer about using `Microsoft.Office.Interop.Word.Application()` to discover the version currently running. – fsbflavio Apr 16 '20 at 14:55