Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:39:44+00:00 2026-05-28T20:39:44+00:00

I am trying to import an XLS file into PHP, where I can then

  • 0

I am trying to import an XLS file into PHP, where I can then edit the information and import it into mySQL. I have never done anything related to this, so I am having a hard time grasping how to approach it.

I have looked at a few open source projects:

  • PHP Excel Reader
  • ExcelRead
  • PHPExcel

None of these options perfectly fit what I want to do or maybe I just haven’t gone deep enough into the documentation.

There are some things that needed to be taken into consideration. The XLS file cannot be converted into any other file format. This is being made for ease-of-access for nontechnical users. The XLS file is a report generated on another website that will have the same format (columns) every time.
For example, every XLS file with have the same amount of columns (this would be A1):

*ID   |Email   |First Name  |Last Name  |Paid    |Active   |State  |Country|*

But, there are more columns in the XLS file than what is going to be imported into the DB.
For example, the rows that are being imported (this would be A1):

*ID   |Email  |First Name  |Last Name  |Country*

I know one of two ways to do edit the data would be A. Use something like PHPExcel to read in the data, edit it, then send it to the DB or B. Use something like PHPExcel to convert the XLS to CSV, do a raw import into a temp table, edit the data, and insert it into the old table.

I have read a lot of the PHPExcel documentation but, it doesn’t have anything on importing into a database and I don’t really even know where to start with editing the XLS before or after importing.

I have googled a lot of keywords and mostly found results on how to read/write/preview XLS. I am looking for advice on the best way of doing all of these things in the least and simplest steps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:39:46+00:00Added an answer on May 28, 2026 at 8:39 pm

    See this article on using PHP-ExcelReader, in particular the short section titled “Turning the Tables”.

    Any solution you have will end up looking like this:

    1. Read a row from the XLS (requires an XLS reader)
    2. Modify the data from the row as needed for your database.
    3. Insert modified data into the database.

    You seem to have this fixation on “Editing the data”. This is just PHP–you get a value from the XLS reader, modify it with PHP code, then insert into the database. There’s no intermediate file, you don’t modify the XLS–it’s just PHP.

    This is a super-simple, untested example of the inner loop of the program you need to write. This is just to illustrate the general pattern.

    $colsYouWant = array(1,2,3,4,8);
    $sql = 'INSERT INTO data (id, email, fname, lname, country) VALUES (?,?,?,?,?)';
    $stmt = $pdo->prepare($sql);
    
    $sheet = $excel->sheets[0];
    // the excel reader seems to index by 1 instead of 0: be careful!
    for ($rowindex=2; $rowindex <= $sheet['numRows']; $rowindex++) {
        $xlsRow = $sheet['cells'][$rowindex];
        $row = array();
        foreach ($colsYouWant as $colindex) {
            $row[] = $xlsRow[$colindex];
        }
        // now let's "edit the row"
        // trim all strings
        $row = array_map('trim', $row);
        // convert id to an integer
        $row[0] = (int) $row[0];
        // capitalize first and last name
        // (use mb_* functions if non-ascii--I don't know spreadsheet's charset)
        $row[2] = ucfirst(strtolower($row[2]));
        $row[3] = ucfirst(strtolower($row[3]));
    
        // do whatever other normalization you want to $row
    
        // Insert into db:
        $stmt->execute($row);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to import this excel file my mysql database, and it
I'm trying to import tariff information from an Excel file into a DataTable to
I am trying to import a CSV file into a MySQL 5.1 database. The
Im trying to import json data to mysql.My json file nearly 3.7Mb and have
I am trying to import an access database to mysql. I have created a
I am trying to import an excel file into a data table using GemBox
I’m trying to import fixed width data from text file into SQL Server Express
I am trying to import a .csv file into my database. I am able
I am trying to import a .csv file into my database. I am able
am trying to read an excel file (i.e xls) and import the data to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.