Easily Export MySQL Data to Excel (.xls) file

Hello guys, previously we have posted a good script to export data from MySQL to CSV File, today we will share another script which would export data from MySQL to excel file. This script would list all the tables of a database in a dropdown and after selecting a table, it would list all the fields of that table so you can select all the fields/columns you want to export in excel file. You would also need to give the name of file which would be exported. So all you need to do is edit script file and setup the database connection and rest would be done by the script.

expport xls


You need to edit db.php file and enter your database username and password. Below is the code that you will have to edit.

Then we have index.php file to display the dropdown of tables in that database. We have used JS to generate the HTML also so it would look a little strange but its fun. If you want you can edit the file and change all functions to there output HTML. Below is our code for index.php

We have used excel.php (credits to matt novac) which generates the excel file. You can download the code and check it yourself, how cool it is 🙂  You can easily use this script whenever you want to export any table data from your dashboard and its very flexible script as it lets you choose which columns of a table you want to export and also give the name of file to be exported.

Hope you will love this easy to use script, comments and suggestions would be appreciated. Also share this post with your friends and followers 🙂

About sanjeev

Dreamer, Blogger and Thinker. I love to help people in solving their problems. You can also join me HERE

Related posts: