先下載PHPExcel套件(這篇是用1.7.X版示範),然後程式碼如下... //程式碼大概就下面七行 ob_start(); include_once('PHPExcel.php'); $obj = new ExcelService(); $html_table = '<table><tr><td>123中文</td></tr></table>'; //要轉成Excel的表格 $html_table = mb_convert_encoding(html_entity_decode($html_table), 'HTML-ENTITIES', 'UTF-8'); //避免中文變成亂碼 $excelFile = $obj->generateExcel($html_table, 'myexcel', 'my_excel_folder'); //產生的Excel的檔名 並指定要放在哪個資料夾 ob_end_clean(); header('Location: my_excel_folder/myexcel.xlsx'); //固定的Class 可以不用改 class ExcelService { public function generateExcel($content, $fname, $tmp_path = '') { if ($fname == '') $fname = date('YmdHis'); if ($tmp_path == '') $tmp_path = 'temp'; $filename = $fname . '.xlsx'; $htmlname = $fname . '.html'; $excelFile = $tmp_path . '/' . $filename; $h...