将表格导出到Excel时如何使用utf-8

时间:2018-11-26 04:56:09

标签: php mysql

我正在尝试将数据导出到excel,表格可以工作,但是语言无法显示

在utf-8中,我是SET CHARACTER SET UTF-8,但它不起作用 我的第一个代码有2个文件

        <form action="/question_export.php" method="post">                  
            <button type="submit" id="export_data" name='export_data' value="Export to excel" class="btn btn-info">تنزيل</button>
        </form>

第二个代码文件是

require_once 'config.php';

$newArray = questions::getAssoc("SELECT * FROM question");

if(isset($_POST["export_data"])) {
    $filename = "export_".date('Ymd') . ".xls";

    header("Content-Type: application/vnd.ms-excel;charset=UTF-8");
    header("Content-Disposition: attachment; filename=\"$filename\"");
    //echo '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
    //echo "\xEF\xBB\xBF"; // UTF-8 BOM
    $show_coloumn = false;
    if(!empty($newArray)) {
        foreach($newArray as $record) {
            if(!$show_coloumn) {
                // display field/column names in first row
                echo implode("\t", array_keys($record)) . "\n";
                $show_coloumn = true;
            }
            echo implode("\t", array_values($record)) ."\n";
         }
    }
    exit;
}

0 个答案:

没有答案