![]() |
want to fetch data in excel sheet from my mysql database
hi all,
i want to fetch my data from database in excel sheet.please anybody help me regarding this problem.. this is my code........ <?php $local = "localhost"; $user = "root"; $pass = "root"; $db = "contact1"; $conn = mysql_connect($local,$user,$pass) or die ("Unable to connect to database."); mysql_select_db($db, $conn); $sql = mysql_query("SELECT * FROM submit"); $result = mysql_query($sql) or die('Error, query failed'); $tsv = array(); $html = array(); while($row = mysql_fetch_array($result)) { $tsv[] = implode("\t", $row); $html[] = "<tr><td>" .implode("</td><td>", $row) .<br> "</td></tr>"; } $tsv = implode("\r\n", $tsv); echo $html = "<table>" . implode("\r\n", $html) . "</table>"; $fileName = 'mysql-to-excel.xls'; header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$fileName"); //echo $tsv; echo $html; mysql_close($conn); ?> :-/ |
Why not do it to CSV, tested and this works for Open Office so it should work for excel (but microsoft being evil, it probably wont), there are also some bits of incorrect code within your example which i have fixed in mine:
PHP Code:
|
hey,
really thankful for ur suggestion ....its wrking fine but if we use the header type Content-type: application/vnd.ms-excel we can easily save our data in .xls file and change the file name too thanks pooja |
| All times are GMT. The time now is 06:06 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0