Code
private string GetConnectionString(string filePath)
{
if (filePath.EndsWith(".xls"))
return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};"
+"Extended Properties='Excel 8.0;HDR=Yes;IMEX=2';", filePath);
if (filePath.EndsWith(".xlsx"))
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};"
+ "Extended Properties='Excel 12.0 Xml;HDR=YES';", filePath);
throw new Exception("wrong file type!");
}
private string GetConnectionString(string filePath)
{
if (filePath.EndsWith(".xls"))
return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};"
+"Extended Properties='Excel 8.0;HDR=Yes;IMEX=2';", filePath);
if (filePath.EndsWith(".xlsx"))
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};"
+ "Extended Properties='Excel 12.0 Xml;HDR=YES';", filePath);
throw new Exception("wrong file type!");
}