C # Error: "Could not find installable ISAM" when converting Excel file to .CSV file

I am working on a project that will be able to convert Excel files to a .CSV file , I think there are some problems in my C # code that also generates an error message. Maybe I can’t find Installable ISAM , please help me figure out my problem.

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 need to put the Data Source between the same cats, but in my case this does not work.

+4
source share
2 answers

Both connection strings are invalid.

For .xlsx this should be:

 StrConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";"; 

(Pay attention to the additional part of Xml, HDR = YES, to indicate that your file has headers, IMEX = 1 to process all data as text and an overridden semi-colony. You will need different connection strings for .xlsm and .xlsb files - see . here )

For .xls, this should be:

 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 colon at the end)

+14
source

The platform plays an important role: if your code is compiled in a 64-bit version and you have 32-bit Office installed (this means that all ODBC, ISAM, etc. drivers are 32-bit). Try compiling with any processor platform

0
source

Source: https://habr.com/ru/post/1493436/


All Articles