简体   繁体   中英

PHP write csv file merge headers

$file_format = "testfile.csv";
$file = fopen($file_format,"w");

$header = array(array('Class Name','Group'));

foreach($header as $fields)
{
    fputcsv($file, $fields);
}

fclose($file);

My question is how do I merge the group cells as image below? 在此处输入图片说明

If you want to manipulate the data then you can use the PHP libraries for handling CSV data link this

but if you need to show the well formatted data then you need to use the .xls file. There are lots of libraries which allows you to handle .xls data. Hope this will help you out.

You can't... a CSV file has no formatting of any kind, including column size.

If you want to control column widths, then you need to write the data to a format that does support columns widths, such as BIFF (.xls) or OfficeOpenXML (.xlsx) or OASIS Open Document Format (.ods) or Gnumeric or other spreadsheet.

From How to set size of column of csv file?

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