h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Set Excel File Format in C#.Net

Set Excel File Format in C#.net

  public static string ExcelFileType()
        {
            string excelFileType = string.Empty;
            Microsoft.Office.Interop.Excel.Application OfficeFileType = new Microsoft.Office.Interop.Excel.Application();
            OfficeFileType.Visible = false;
            string oVersionName = OfficeFileType.Version;
            int length = oVersionName.IndexOf('.');
            oVersionName = oVersionName.Substring(0, length);
            int versionNumber = int.Parse(oVersionName, CultureInfo.GetCultureInfo("en-US"));
            if (versionNumber >= 12)
            {
                excelFileType = ".xlsx";
            }
            else
            {
                excelFileType = ".xls";
            }

            return excelFileType;
        }