Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Make bold text in PHP exported .xls file

Tags:

php

xls

I am working in core PHP. I need to make header text in bold format and remains normal text format. The .xls file will be export from PHP.

I am not using any plug-in in my project. I need to complete this without using any plug-in. But i unable to solve this.

My code as follows,

//header part cration
while($r=mysql_fetch_array($exe))
{
    //need to set bold. But it is not working. it giving error
    //$header .= "<b>".$r['question']."</b>"."\t ";

    $header .=.$r['question']."\t ";
}

//body part cration
while($r=mysql_fetch_array($exe))
{
    $data .= $r['answer']."\t ";
    //code continuous...
}

and Exporting code as follows,

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=reports.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n\n$data";

Exporting file working fine. But i unable to make headers are bold.

Please any help much be appreciated.

like image 902
VijayS91 Avatar asked Dec 03 '12 18:12

VijayS91


1 Answers

One potential option would be to have your PHP code generate an HTML table model that includes your formatting on specific cells. Then have PHP save the file as an XLS document and Excel should be able to open that with the formatting applied.

It might not be the most elegant solution, but it looks like has been done before.

I can see why many people suggest using a plugin.

like image 150
Jeff Jenkins Avatar answered Oct 26 '22 11:10

Jeff Jenkins