简体   繁体   中英

Is it possible to make headings text bold while export to csv using fputcsv?

I am working on export to csv sheet requirement, Its working fine data is getting exported to CSV sheet but all the data including titles on top of the sheet for each column and normal data exported as a normal text. What I want here is obviously all the titles should be in bold text. Is it possible to export all titles in bold colour?

My code:

$list[] = 'Title-1,Title-2,Title-3,Title-4'; // I want these titles in bold text
foreach ($result as $ck => $user_data) {
  $list[] = $user_data['val-1'] . ',' . $user_data['val-2'] . ',' . $user_data['val-3']. ',' . $user_data['val-4'];
}
ob_clean();
$fileName = 'file_name.csv';
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment;filename=' . $fileName);
$file = fopen("contacts.csv", "w");
$file = fopen('php://output', 'w');
foreach ($list as $line) {
  fputcsv($file, explode(',', $line));
}
fclose($file);
exit;

some people are saying bold is not possible in CSV file & supports only plain text but it does, for your reference I am attaching a screenshot. please see it在此处输入图片说明

I am using 'fputcsv()' for export into csv sheet. Any help. Thanks.

No, it is not possible to do so in CSV. CSV is like a plain text without any formatting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM