PHP中常用的导出数据的方法有:
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="data.csv"');
echo "Name,Age\n";
echo "Alice,25\n";
echo "Bob,30\n";
$file = fopen('data.csv', 'w');
fputcsv($file, array('Name', 'Age'));
fputcsv($file, array('Alice', 25));
fputcsv($file, array('Bob', 30));
fclose($file);
echo '<a href="data.csv" download>Download CSV</a>';
require 'PHPExcel.php';
$excel = new PHPExcel();
$excel->setActiveSheetIndex(0)
->setCellValue('A1', 'Name')
->setCellValue('B1', 'Age')
->setCellValue('A2', 'Alice')
->setCellValue('B2', 25)
->setCellValue('A3', 'Bob')
->setCellValue('B3', 30);
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save('data.xlsx');
echo '<a href="data.xlsx" download>Download Excel</a>';
这些方法可以根据需要选择合适的方式来导出数据。