C #

Source: Internet
Author: User

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 #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.