0

I have this code to get date from my database und get this as a csv file:

<?php

    header('Content-Encoding: UTF-8');
    header('Content-Type: text/csv; charset=UTF-8');
    header('Content-Disposition: attachment; filename=export.csv');
    echo "\xEF\xBB\xBF"; // UTF-8 BOM
    $output = fopen('php://output', 'w');
    
    
    
    $sql = 'SELECT * FROM `myTable`'; 
    $result = $db->query( $sql ); 
    
    while ($zeile = $result->fetch_object()) {
        
        $myData[] = array (
            'column_A'  => $zeile->value_A,
            'column_B'  => $zeile->value_B
        );
        
    }
    
    
    
    foreach ($myData as $data) {
       fputcsv($output, $data, ";");
    }
    
    ?>

This works fine !

But now I need a file, which has more the one sheet. CSV can't handle this, so I need a xlsx file instead a csv file.

How can I export my data (like above) as a xlsx file with different sheets ? Thanks !!

Trombone0904
  • 4,132
  • 8
  • 51
  • 104

0 Answers0