您的位置:首页 > 其它

ADO.NET操作Excel的连接字符串

2009-11-18 18:07 489 查看
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!");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: