Import the contents of a text file (TXT) into Excel and SQL

Source: Internet
Author: User

These two days on the network circulated 14w 12306 account information txt document, downloaded and found in the TXT document and query content is not very convenient.

Here I am documenting the process of importing TXT documents into Excel and SQL.

Import to Excel

1. Create a new Excel and select from text in the data option of the Ribbon:

2. Text Conversion Wizard for Excel:

Step 1: Use the default options

Step 2: Select the delimiter, the delimiter in TXT is---, but only one "-" symbol can be entered here

Step 3:

This is the end of importing from TXT to Excel, but because the delimiter we enter is a single "-", there are a lot of extra columns in Excel, and the last to delete:

Import into SQL import into SQL preprocessing

1. If we look closely at the ID of an Excel column, we find that Excel defaults to setting this column as a number format, and because the numbers are too large, they are also shown as scientific notation.

But some IDs have the last character "X", so this column should be converted to a text type, or the "X" in the process of importing SQL will become a null value.

The conversion process is as follows:

In the last item of the Conversion Wizard, select the following column format:

2. In the first column in Excel, add the header, which is later imported into SQL to act as the corresponding SQL table field role.

Formally Import SQL

1. Select Import Data:

2. Select the data source for Excel:

3. Select the worksheet to import into Excel and set the table name to import the database:

4. Import the Mapping settings for SQL fields and Excel columns to remove some empty Excel columns

5. View the results of the run

6. Finally, you can write the SQL statement query directly:

Summarize

Import into SQL and Excel can also be implemented in code, but the existing tool implementation is quite handy, the last benefit map:

Import the contents of a text file (TXT) into Excel and SQL

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.