I am using a PHP script to export data from MySQL into Excel.
The first row of the Excel sheet is a column heading. I want them to appear in bold. How do I do this?
I am using the following code:
$con = mysql_connect("localhost","admin","password");
if (!$con)
{
die('Could not connect to DB: \n' . mysql_error());
}
mysql_select_db("ALNMSI", $con);
$result = mysql_query("SELECT * FROM survey1");
$filename = "alnmsi_" . date('d-m-Y') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel"); $flag = false;
$flag = false;
while($row = mysql_fetch_array($result))
{
if(!$flag)
{
data_keys();
$flag = true;
}
array_walk($row, 'cleanData');
data_array($row);
}
I’m assuming you are doing it wrong. Whatever you output it’s probably not a valid Excel file, since you didn’t mention BIFF (this is the binary format which Excel files would be made of).
If you output TAB or COMMA separated values, then Excel only accidentially opens it correctly. And there is no way to style headers.
Also read: