How to make bold text in exported PHP .xls file

I work mainly PHP. I need to make the header text in bold and keep the normal text format. The .xls file will be exported from PHP.

I do not use the plugin in my project. I need to accomplish this without using any plugin. But I canโ€™t solve it.

My code is 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 Export 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"; 

File export works fine. But I canโ€™t make the headlines bold.

Please help with the rating.

+6
source share
1 answer

One possible option would be for your PHP code to generate an HTML table model that includes formatting on specific cells. Then, PHP will save the file as an XLS document, and Excel should open it using formatting.

This may not be the most elegant solution, but it looks up to .

I see why many people suggest using a plugin.

+2
source

All Articles