0

I'm using http headers declaring that content, then I am using the PHP function fputcsv to output data:

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=organisation.csv");
header("Cache-Control: must-revalidate");
header("Pragma: must-revalidate");
header('Expires: 0');
header('X-Content-Type-Options: nosniff');
$file = fopen('php://output', 'w');
fputcsv($file, array('Post ID', 'Post title', 'URL'));

When I run this is exporting data correctly. However I would like to split the data into different sheets/tabs within the csv.

Is this at all possible?

  • 3
    CSV files are flat files, they don't have sheets or tabs. If you want to create a more complicated Excel file (xls), you'll need an excel library. – aynber Oct 31 '22 at 16:39
  • 1
    Does this answer your question? [PHP exporting data to CSV in multiple sheets](https://stackoverflow.com/questions/29934448/php-exporting-data-to-csv-in-multiple-sheets) – Chris Haas Oct 31 '22 at 17:28
  • Thanks @ChrisHaas, certainly pointing me in the right direction. – Neil Watson Nov 01 '22 at 08:48

0 Answers0