Home » PHP » Read Excel file and save details to database using PHP-Repost

Read Excel file and save details to database using PHP-Repost

How can you read excel file using php and save that details to the database? My other post is describing Read Excel file and save details to database using PHP.But it is not properly working in new version of excel 2007..etc.My readers are asked to do this for other excel versions.So I’m going to show how to read any format of excel file like 97-2003(xls) or 2007 (xlsx) formats excel files. Also I’ll show how to create/write excel file using php.

In here I’m using different library to do this.That is the “PHPExcel” Library.


Creating the Database Connection


Including files and libraries

My Excel file is like this.


Call to the functions to read excel file


Display sheet data

Final result is like this.


Save details to the database

Here, I’m customizing the above loop to insert details to the database.
This is the table structure.

That’s only. All are done.

Additional Details

Set Sheet number

Get number of rows

Get number of columns

Get specific cell address value/text

Get specific cell calculated value/formula value


-This is working for excel 97-2003 , 2007 and latest format of the excel files.
-If you have suggestions, idea, questions…etc please leave a comment below.
-I am suggesting check the library files and folders then you can get the more information than this.
-In the next post, I’ll show you how to write/create excel file and insert data to it using php.

Here is the full source code to download.

Download Read Excel file Full source Code (920 KB)


Similar posts

  • west

    hello what happens if you have special characters like “?,?,รณ,?”?

  • saurabh

    when i run this code it is showing error like this

    Class ‘PHPExcel’ not found in C:Program FilesEasyPHP-DevServer-14.1VC9datalocalwebexcel_demoPHPExcelReaderExcel2007.php on line 351

    • Hello saurabh,
      ‘PHPExcel’ class is including in the “PHPExcel.php” file. So check this class file you have included.That’s why displaying this error.

      /** PHPExcel_IOFactory */
      include ‘PHPExcel/IOFactory.php’;


  • Vivek ab

    download link not working

  • partha chowdhury

    running “index.php” file following error showing

    Error loading file “users.xlsx”: ZipArchive library is not enabled

    how to solve this issue. kindly suggest me.

    stepwise instructions would be apprecitaed…

    • Try to add,


      right after the line,

      require_once ‘path/to/PHPExcel.php’;

      or before any instanciation of the PHPExcel class.

      • dev

        in which file do we have add this line

      • dev

        in the file Classes/PHPExcel/Settings.php
        line no 122:
        i returned true, still same error could not open file .
        if u can give a brief instructions how to resolve it

  • pradeep

    Hello sir this is working fine but date field coming 42232 ..how fix this problem.

  • dhara inamdar

    hello I am getting error of: Unable To read file abc.xlsx :File does not Found

    • check the path of abc.xlsx. this error bcs of above abc.xlsx file is not loaded correctly.

      • dhara inamdar

        I am taking the .xlsx file from upload button(UploadSheet) submit event , So taking file name in load method as,

        $objPHPExcel = $objReader->load($_FILES[‘UploadSheet’][‘name’]);

        so is it wrong? then how sould i take filename with path in load method?