Solve the problem that "string" and "Number" formats exist simultaneously in the same column and cannot be correctly displayed during reading: Set xlsconn = Createobject ("ADODB. connection ") xlsconn. open "provider = Microsoft. jet. oledb.4.0; Data Source = "& server. mappath (xlspath) & "; extended properties =" "Excel 8.0; HDR = yes; IMEX = 1 """
It is mainly about the driver. You need to add HDR and IMEX,
The HDR value is yes and no, indicating whether the first row is a field name.
IMEX value: 1, 2,
1 is the key to solving this problem.
"HDR = yes;" indicates that the first line contains the column name, not the data;
"IMEX = 1;" Notification driver
Data columns are always read as text.
Both must be used together.
If not, use the following method:
I thought it would be okay. However, in actual use, this setting still does not work. After reading a lot of information, we found that there was another information in the registry that needs to be modified, in this way, the content of the first eight rows can no longer be used in Excel to determine the type of the column.
Modify the Registry as follows:
There is a typeguessrows value in HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ jet \ 4.0 \ engines \ excel. The default value is 8, indicating that the first eight columns will be read to determine the type of each column, therefore, if the first eight columns of data are all numbers, the text that appears after the first eight columns will become null. To solve this problem, you only need to change the typeguessrows server code value to 0, you can solve this problem.
Oledbconnection starts from index 166 and the format of the initialized string is invalid.
When the Excel connection prompt starts from index 166, the format of the initialization string is invalid.
The connection string is string. format (@ "provider = Microsoft. ace. oledb.12.0; persist Security info = false; Data Source = {0}; extended properties = \ Excel 12.0; HDR = yes; IMEX = 1; \ ", filepath );
The error occurs because the content in extended properties is not enclosed by quotation marks.
String. format (@ "provider = Microsoft. ace. oledb.12.0; persist Security info = false; Data Source = {0}; extended properties = "" Excel 12.0; HDR = yes; IMEX = 1; "", filepath );
C #