sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + fileName + ";" +
"Extended Properties='Excel 12.0;HDR=YES;'";
格式不兼容,导出为Office Open XML
sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + fileName + ";" +
"Extended Properties='Excel 12.0 Xml;HDR=YES;'";
Microsoft.ACE.OLEDB.12.0下载地址:http://www.microsoft.com/downloads/zh-cn/details.aspx?displaylang=zh-cn&FamilyID=7554f536-8c28-4598-9b72-ef94e038c891
03版:
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileName + ";" +
"Extended Properties=Excel 8.0;";
saveFileDialog.Filter = "Excel2003 files (*.xls)|*.xls|Excel2007 (*.xlsx)|*.xlsx|Excel2007二进制表 (*.xlsb)|*.xlsb";
...
if (fileName.EndsWith("xls"))
{
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileName + ";" +
"Extended Properties=Excel 8.0;";
}
else if (fileName.EndsWith("xlsx"))
{
sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + fileName + ";" +
"Extended Properties='Excel 12.0 Xml;HDR=YES;'";
}
else if (fileName.EndsWith("xlsb"))
{
sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + fileName + ";" +
"Extended Properties='Excel 12.0;HDR=YES;'";
}
源自:http://www.cnblogs.com/TrueElement/archive/2012/02/17/2355923.html
还没有评论,登录后来说两句。