How to export data in excel format in Codeigniter using PHPExcel Library

Dear Reader, let us we know that “How to export data in excel format using Codeigniter“  Using PHPExcel Library So in this Tutorial We Learn Step By Step  How to export data in excel format using Codeigniter Process.

An Excel worksheet is a collection of cells where you can keep and manipulate data. Each Excel workbook can contain multiple worksheets.If we want to maintain an Excel worksheet of our website data then we have the option to type one by one data in our excel worksheet, for this provision today we know how to export data from database in Excel sheet using Codeigniter.

First, we see Snapshots of our Export data to Excel format


Step 1:- First of all you need to create the database like ci_demo

Step 2:- Now create a table “mobiles” in a database using the below SQL code

Step 3:- Now dump some data for table “mobiles” using bellow SQL code

Step 4:- Now we need to download PHPExcel library here and extract this in application third_party folder as we can see in below snapshot


Step 4:- Now we need to create a library for load PHPExcel library, create Excel.php file in library folder and paste the below code

Step 5:- Now we will see our controller, so create an Exports Controller in your CI application like Exports.php(Controller)

First, create a constructor in__construct() this we will load our necessary libraries.

Step 6:- In Exports.php Controller first we need to create Index method in this function we will retrieve data from our database(models) and will pass this data to the respective view.

Step 7:- Now we need to create methodcreateXLS(), this function used to create an excel file and show records from MySQL database.

Step 8:- Now here is a Complete code of Exports.php Controller, create your Controller file like Exports.php and paste below code

Step 9:- Now we need to create Export.php Model and paste below code

Step 10:- Now here view code Create exports/exports.php(view) file and paste the below code

Now run your project, so you need to type in browser localhost/your_project_name/exports


http://localhost/ci_demo/exports then you can see the result as in below snapshot, you can Export data by click on Export Data button


Congratulations you have successfully created Export to Excel MySQL data into excel sheet in Codeigniter using PHPExcel library, if you like this post and was helpful for you then share this post on social media and if you have any query then please contact us or comment below, Thanks.



  • do an essay November 11, 2017

    I know this website presents quality based articles or
    reviews and extra information, is there any other web site which gives these kinds of
    things in quality?


    • Webpreparations Team November 13, 2017

      Thanks Dear Reader,
      Yes of course, you can also follow .This is our another Blogging Website.


  • gmail login November 30, 2017

    At this time it seems like Movable Type is the best blogging platform available right now.
    (from what I’ve read) Is that what you are using on your blog?


    • Webpreparations Team December 12, 2017

      Thanks dear Reader 🙂


  • NobGorgo December 13, 2017

    hello!,I like your writing very much! share we communicate more about your post on AOL? I require a specialist on this area to solve my problem. May be that’s you! Looking forward to see you.


    • Webpreparations Team December 22, 2017

      Thanks a lot dear Reader, you can contact us.


  • Jewelry March 29, 2018

    I don’t even know how I ended up here, but I thought this post was great. I do not know who you are but definitely you’re going to a famous blogger if you are not already 😉 Cheers!


    • Webpreparations Team March 29, 2018



  • Home Improvement March 29, 2018

    Thank you for sharing excellent informations. Your web-site is so cool. I am impressed by the details that you have on this site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found simply the information I already searched all over the place and simply couldn’t come across. What an ideal web site.


    • Webpreparations Team March 29, 2018



  • Home Improvement March 31, 2018

    Just desire to say your article is as astonishing. The clearness in your post is just excellent and i can assume you are an expert on this subject. Well with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please carry on the rewarding work.


    • Webpreparations Team April 02, 2018

      Dear Reader, Thanks for appraising. If you wanna be our subscriber then please subscribe yourself from Newsletter widget by providing your email address there. Thanks again 🙂


  • Hussam October 20, 2018

    i get the following error message in my log file:
    PHP Fatal error: Class ‘ZipArchive’ not found in ( knowing that the code works fine in my localhost, but i face this problem in godaddy shared hosting )
    how i can solve it ?


    • Webpreparations Team October 20, 2018

      This is server’s problem, please contact to Goddady support team, they will resolve your issue.
      For more help please comment here.
      Thank you for contact us.


  • fyzan November 05, 2018

    Thank you for sharing this, what if i need to download multiple files in on submit. how to loop it so it can download all files or zip them to download.


  • harshal December 06, 2018

    Unable to load the requested class: Excel


    • Webpreparations Team December 06, 2018

      What is the error message?


Leave a comment:

Your email address will not be published. Required fields are marked *