public string BuildExcelConnectionString(string filename) {
string ext = System.IO.Path.GetExtension(filename);
// Support for Excel 2007 XML format
if (ext.ToLower() == ".xlsx")
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES\";", filename);
// Support for Excel 2007 binary format
if (ext.ToLower() == ".xlsb")
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0;HDR=YES\";", filename);
// Support for Excel 2007 binary format
if (ext.ToLower() == ".xlsm")
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Macro;HDR=YES\";", filename);
// Basic support for Excel 97 through 2003.
return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=YES\";", filename);
}
string ext = System.IO.Path.GetExtension(filename);
// Support for Excel 2007 XML format
if (ext.ToLower() == ".xlsx")
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES\";", filename);
// Support for Excel 2007 binary format
if (ext.ToLower() == ".xlsb")
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0;HDR=YES\";", filename);
// Support for Excel 2007 binary format
if (ext.ToLower() == ".xlsm")
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Macro;HDR=YES\";", filename);
// Basic support for Excel 97 through 2003.
return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=YES\";", filename);
}