Solution C # reading numbers in Excel cannot be read

Source: Internet
Author: User

I wrote a tool to generate SQL scripts based on the Excel Data dictionary, and encountered some minor problems during the process.

Cannot read data cells in Excel. Data is available, but all read results are null.

Solution:

1. in the import data connection string, add IMEX = 1, "provider = Microsoft. jet. oledb.4.0; Data Source = "C: \ data.xls"; extended properties = "Excel 8.0; HDR = yes; IMEX = 1.

Note:

IMEX = 1: Mixed Mode
HDR = yes; whether to use the first row as the column header

Both must be used together.

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 HKLM \ 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!

 

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.