Posts

Showing posts from September, 2015

Generate Excel Sheet in PHP

Hello readers, in this post we are going to see the code to  generate excel sheet in PHP by exporting contents from database i.e., directly outputting your query result to excel sheet (.xls file) and adjusting HTTP header fields <?php// DATABASE DETAILS$DB_USERNAME="root";$DB_PASSWORD="root";$DB_HOST="localhost";$DB_NAME="local_test";//ESTABLISHING CONNECTION$conn=mysql_connect($DB_HOST,$DB_USERNAME,$DB_PASSWORD);$db=mysql_select_db($DB_NAME,$conn);if(!$conn)die("Sorry colud not connected to database");$query="SELECT * FROM MY_TABLE";//FIRING QUERY AND COLLECTING RESULT$result = mysql_query($query);// Header info settingsheader("Content-Type: application/xls");header("Content-Disposition: attachment; filename=output.xls");header("Pragma: no-cache");header("Expires: 0");// Define separator (defines columns in excel &amp; tabs in word)$sep = "\t"; // tabbed character// Sta