Reputation: 1845
How to set color to header when creating XLS using php,see below code can anyone guide me how to do it.thanks
$sql_select= "******";
$queryRes = mysql_query($sql_select);
//print $sql_select;
$header = "Country" . "\t";
$header .= "Network" . "\t";
$header .= "MCC" . "\t";
$header .= "MNC" . "\t";
$header .= "ClientPrice" . "\t";
$header .= "Currency" . "\t";
//Reading the data thro' POST
$data="";
$data1 = array();
$data1[]= "Country";
$data1[]= "Network";
$data1[]= "MCC";
$data1[]= "MNC";
$data1[]= "ClientPrice";
$data1[]= "Currency";
$data= join("\t", $data1)."\n";
while( $row = mysql_fetch_assoc($queryRes)){
$row1 = array();
$row1[] = $row['country'];
$row1[] = $row['networkname'];
$row1[] = $row['mcc'];
$row1[] = $row['mnc'];
$row1[] = $row['clientprice'];
$row1[] = $row['currency'];
$data .= join("\t", $row1)."\n";
//$data= $first_name."\t";
//$data .= $row['originator']."\t";
}
$attachment_current= "Price Notification "."_$attachment_date";
file_put_contents("/data/data/www/fms/pricelists/$attachment_current.xls",$data);
//print "$header\n$data";
Upvotes: 0
Views: 3826
Reputation: 212402
You're not creating an Excel file, you're creating a CSV file (tab separated in this case), and that format does NOT support any kind of formatting (font, color, even merging cells isn't an option).... and you're not even using PHP's built-in fputcsv() function to do so :(
Simply giving a file an extension of .xls doesn't make it an Excel file. MS Excel is capable of reading CSV files, but some versions of Excel will actually warn you that the format isn't correct when you load it.
Create a proper Excel BIFF or OfficeOpenXML file using one of the many libraries available to do so (such as PHPExcel), and then you'll be able to set formatting such as cell background colours.
Upvotes: 3