在将表导出到excel时如何使用utf-8

agyaoht7  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(207)

我正在尝试将数据导出到excel中,表格可以工作,但语言不能显示
在utf-8中,我是用户集字符集utf-8,但它不工作,我有两个文件的第一个代码

<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;
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题