$filename = 'Training-All';
header('Content-Encoding: utf-8');
header("Content-Type: text/xls; charset=utf-8");
header("Content-Transfer-Encoding: binary");
header("Content-Type: application/xls");
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Content-Type: application/force-download");
header("Pragma: no-cache");
header("Expires: 0");
// กรณีที่ต้องการทำให้เป็นภาษาไทยให้ใส่ echo นี้ไว้ก่อน text
echo "xEFxBBxBF";
ถ้าเป็น xls จะต้องมี header meta ของ html แล้วก็ใช้งานโครงสร้าง table ได้เลย
แต่ถ้าเป็น csv แบ่งตารางด้วย , และจัดการบรรทัดด้วย แบ็คแสลทเอ็น