XLS to MySQL by selecting Columns

Posted on 2007-10-01
Last Modified: 2013-12-13
Hi experts. I have an XLS file (Excel) which has 90 columns. I want to import into a MySQL database the columns 0,1,2,30,65,68,90. How can I do that?
Question by:netrinogr
    LVL 11

    Expert Comment


    As long as there are no comma characters in your data, save the excel spreadsheet as a CSV (Comma Delimited) file.  This is a text version of your excel spreadsheet.

    Then you can use PHP code to read the csv file one line at a time, splitting the line on the comma character, and reading only the columns you want, then writing these columns into your MySQL database.

    However, although the code is simple, it's still a couple of hours work, so I recommend you use an excellent free tool at  This is a simple PHP script that you just configure to connect to your database, and away you go.

    If this doesn't work for you, post back and I'll write some example code for you, or look at alternative solutions.
    LVL 50

    Accepted Solution

    Even easier.

    Export the spreadsheet as a delimited file.  Try to use a delimiting character that does not appear in any of the text, but delimited quoted strings is fine, too.  Copy the file to the MySQL server, and import it using the LOAD DATA INFILE syntax (  Once the data is in a table, simply delete any columns you don't want.

    15 minutes of work if you know what you're doing.  Maybe a little longer to look up syntax if you need to.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now