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;
}
{
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;
}