alexcmm Posted November 19, 2006 Share Posted November 19, 2006 I'd like to know if there's a way to export the contents of my table to excel that allows you to format the outputted excel file. I have found code that exports, but it's not pretty... Here's how that looks... Thanks!![b]<?php header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=FILENAME.xls"); header("Pragma: no-cache"); header("Expires: 0"); include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); $select = "SELECT * FROM $usertable WHERE hide='no'"; $export = mysql_query($select); $count = mysql_num_fields($export); for ($i = 0; $i < $count; $i++) { $header .= mysql_field_name($export, $i)."\t"; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r", "", $data); if ($data == "") { $data = "\n(0) Records Found!\n"; } print "$header\n$data"; ?> [/b] Link to comment https://forums.phpfreaks.com/topic/27787-export-to-excel-pretty/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.