c# 错误:将 Excel 文件转换为 .CSV 文件时“无法找到可安装的 ISAM”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17858759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
c# Error: “Could Not Find Installable ISAM” in converting Excel file into .CSV file
提问by user1863359
I'm working on a project that would be able to convert Excel files to .CSV File, I think there are some problems in my C# code that is generating and error message Could Not Find Installable ISAM, please help me to sort out my problem.
我正在开发一个能够将 Excel 文件转换为 .CSV 文件的项目,我认为我的 C# 代码中存在一些问题,并且正在生成错误消息无法找到可安装的 ISAM,请帮我解决我的问题.
Code:
代码:
if (dlgOne.FileName.EndsWith(".xlsx"))
{
StrConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 12.0;\"";
}
if (dlgTwo.FileName.EndsWith(".xls"))
{
StrConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 1.0;HDR=Yes;IMEX=1\"";
}
OleDbConnection conn = null;
conn = new OleDbConnection(StrConn);
conn.Open(); <------------ throw exception
In debug mode the application throws an exception(line: conn.Open();
)
I searched the Internet and I found that I have to put the Data Source
between one cotes but it doesn't work in my case.
在调试模式下,应用程序抛出异常(行:)conn.Open();
我在互联网上搜索,我发现我必须把Data Source
一个 cotes放在一个 cotes 之间,但它在我的情况下不起作用。
采纳答案by barrowc
Both of the connection strings are wrong.
两个连接字符串都是错误的。
For .xlsx, it should be:
对于 .xlsx,它应该是:
StrConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";";
(Note the extra Xml part, the HDR=YES to indicate your file has headers, the IMEX=1 to treat all data as text and the repositioned semi-colon. You would need different connection strings for .xlsm and .xlsb files - see here)
(注意额外的 Xml 部分,HDR=YES 表示您的文件有标题,IMEX=1 将所有数据视为文本和重新定位的分号。对于 .xlsm 和 .xlsb 文件,您需要不同的连接字符串 - 请参阅在这里)
For .xls, it should be:
对于 .xls,它应该是:
StrConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";";
(Note the change from Excel 1.0 to Excel 8.0 and the addition of a semi-colon at the end)
(注意从 Excel 1.0 到 Excel 8.0 的变化,并在末尾添加了一个分号)
回答by PricklyMaster
Platform plays an important role: if your code compiles in 64-bit and you have Office 32-bit installed (which means all ODBC, ISAM, etc. drivers are 32-bit). Try compiling with "Any CPU" platform
平台起着重要作用:如果您的代码以 64 位编译并且您安装了 Office 32 位(这意味着所有 ODBC、ISAM 等驱动程序都是 32 位)。尝试使用“Any CPU”平台进行编译