ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • c# 엑셀 버전 찾기
    Development Programs 2022. 11. 18. 13:46
    반응형

    /// <summary>
            /// 엑셀 버전찾기
            /// </summary>
            /// <returns></returns>
            /// <remarks>
            ///  8  = 97
            ///  9  = 2000
            ///  10 = 2002
            ///  11 = 2003
            ///  12 = 2007
            ///  14 = 2010
            ///  15 = 2013
            ///  16 = 2016
            ///  18 = 2019
            ///  18 = offcie365
            /// </remarks>
            public static int GetExcelVersion()
            {
                try
                {
                    RegistryKey subKey = Registry.ClassesRoot.OpenSubKey(@"Excel.Application\CurVer");
                    if (subKey != null)
                    {
                        try
                        {
                            string[] temp = ((string)(subKey.GetValue(""))).Split('.');
                            int excelVersion;
                            if (int.TryParse(temp[temp.Length - 1], out excelVersion))
                            {
                                return excelVersion;
                            }
                            return 0;
                        }
                        catch
                        {
                            return 0;
                        }
                    }
                    return 0;
                }
                catch (System.Exception ex)
                {
                    return 0;
                }
            }

     

     

    t사용예 

    if (HelperUtil.GetExcelVersion() <= 12)
                    {
                        connectionString = string.Format(Excel03ConString, filePath, header);
                    }
                    else
                    {
                        connectionString = string.Format(Excel07ConString, filePath, header);
                    }

    반응형

    댓글

Designed by Tistory.