0
$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

3
  • what does the csv look like now and what do you want it to look like after ? Commented Aug 28, 2015 at 3:14
  • Can't do anything without seeing a sample of the data... (as Dagon said above) Commented Aug 28, 2015 at 3:18
  • 1
    csv is a data exchange format and can't control the formatting of cells in excel Commented Aug 28, 2015 at 3:48

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.