Working on something totally new to me. Exporting MySQL data to Excel. Have it working great but wondering if I can format the cells...ie. format the price column as prices (just have it stored as plain numbers in the db) perhaps bold and bg color the headers. This is what I have for the code...the xls is generated from a link on the page.
<?
include("db_connect.php");
//query for toy list
$vquery = mysql_query("SELECT BROKER,BOATYEAR,BOATLENGTH,BOATMAKE,BOATMODEL,BOATPRICE,NADA,LASTCHANGE,STATUS
FROM VESSEL ORDER BY BROKER");
$vrows = mysql_num_fields($vquery);
//get row headers
for ($i = 0; $i < $vrows; $i++) {
$header .= mysql_field_name($vquery, $i)."\t";
}
//get data
while($row = mysql_fetch_row($vquery)) {
$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);
//check if data exists
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Inventory.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
Can this be done? I ahve seen several ways to get a dump into Excel and got this working but don't know if i can format the dump for the spreadsheet.