C#错误:在转换Excel文件到.CSV文件“找不到可安装ISAM” [英] c# Error: “Could Not Find Installable ISAM” in converting Excel file into .CSV file
问题描述
我工作的一个项目,该项目将能够转换成Excel文件转换为.csv文件,我想有我的C#代码中的一些问题,这些问题是产生和错误信息的莫非。找不到安装ISAM ,请帮我理清我的问题。
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.
代码:
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
在调试模式下应用抛出的例外(行: conn.Open();
)
我在网上搜索,我发现我必须把数据源
一柯特斯但它并不在我的情况下工作。
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.
推荐答案
这两种连接字符串是错误的。
Both of the connection strings are wrong.
有关的.xlsx,它应该是:
For .xlsx, it should be:
StrConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";";
(注意额外的xml的一部分,HDR = YES,表示你的文件有报头,该IMEX = 1把所有的数据,文本和重新定位分号你会需要.XLSM和.xlsb文件,不同的连接字符串 - 参见这里)
有关.xls的,它应该是:
For .xls, it should be:
StrConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";";
(注意:从Excel 1.0到Excel 8.0的变化,并在年底增加了一个分号)
(Note the change from Excel 1.0 to Excel 8.0 and the addition of a semi-colon at the end)
这篇关于C#错误:在转换Excel文件到.CSV文件“找不到可安装ISAM”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!