KKL Michael
KKL Michael

Reputation: 795

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? enter image description here

Upvotes: 0

Views: 5328

Answers (2)

Ashish Ranade
Ashish Ranade

Reputation: 605

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.

Upvotes: 1

Abdallah Alsamman
Abdallah Alsamman

Reputation: 1672

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?

Upvotes: 1

Related Questions