Excel Sheet Data Upload to Database in Codeigniter

Let’s see how to upload Excel Sheet multiple row Data to Database with single query in Codeigniter.

First make a View to selecting the excel file:

This form will transfer to the controller method where we have to upload excel sheet and add sheet data to database:

At first get the Codegniter validation for uploading excel file and display error message if validation fail:

Now we have to add PHPExcel library to our codeigniter project to get data from excel file. You can download PHPExcel library. And add that library to Application\Libraries folder like this:


Load this library to our controller construct method:

Now we have to get the data from excel sheet, so create the object of the library and load the excel file that we upload our desired path. Get the Active sheet Index and pass that sheet whole data with an array to Model method where we have to add data to the table.

Now in the model method we have to create for loop to get the whole data and put it into the array.

At last we have to add just one line with codeigniter functionality to generate the query and add it to the database.

Here insert_batch(‘table_name’, ‘data’) generate the query like this:

And you can see the excel sheet data added to the database.

  • Peace Juma

    I want to upload data in excel sheet in codeigniter