C#连接Excel提示“外部表不是预期的格式”

来源:互联网 发布:网红美妆淘宝店前十名 编辑:程序博客网 时间:2024/06/07 14:22

Office2003(Microsoft.Jet.Oledb.4.0)
string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", strExcelFileName);

Office2007(Microsoft.ACE.OLEDB.12.0)
string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", strExcelFileName);

Office2010(Microsoft.ACE.OLEDB.12.0)
string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'", strExcelFileName);

还要一个就是“HDR=Yes”这个问题,如果HDR的值是Yes,那么第一行是被当做列名的,不会被导入。只有为“No”才可以被当做数据导入。

0 0
原创粉丝点击