-1

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);
}
7
  • does Excel not format docs excessively like Word does? Commented Jan 10, 2011 at 6:57
  • i.e. Excel might not accept raw text..... Commented Jan 10, 2011 at 6:57
  • no excel does accept raw text, the excel file is being created properly now i want to introduce a bit of formatting in the excel file. i need the first row to be in bold Commented Jan 10, 2011 at 6:59
  • what library are you using to generate excel file? Commented Jan 10, 2011 at 7:04
  • i am not using a library, the headers i am using informs the browser that instead of the output being displayed on the web page it shgould be downloaded into and .xls file Commented Jan 10, 2011 at 7:06

2 Answers 2

4

You should use a library to generate Excel files.

Sign up to request clarification or add additional context in comments.

3 Comments

the pear excel writer appears to only work upto excel5.0 not 7.0.
also i dont want to introduce such completixity into my code so as to use PHPExcel classes. Is there no other way i can use the html bold and underline tags to do this ?
I think you will add more complexity trying to avoid such librairies. If you are building new files I do not see the problem. Excel 7 is able to open excel 5 files.
3

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:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.