Php output excel Chinese garbled problem?

function xlsBOF() {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
}
function xlsEOF() {
    echo pack("ss", 0x0A, 0x00);
}
function xlsWriteNumber($Row, $Col, $Value) {
    echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
    echo pack("d", $Value);
}
function xlsWriteLabel($Row, $Col, $Value) {
    $L = strlen($Value);
    echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
    echo $Value;
}

ob_end_clean();
ob_clean();
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Transfer-Encoding: binary");
$filename = urlencode("export_".date("Y-m-d-His").".xls");
header("Content-Disposition: attachment; filename=".$filename."");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
header("Pragma: public");

xlsBOF();

xlsWriteLabel(0, 0, "");
xlsWriteLabel(0, 1, "");
xlsWriteLabel(0, 2, "");

$order = $pdo->query(
  "SELECT * FROM `order_record` as r "
);
$i = 1;
while ($row = mysqli_fetch_array($order)) {
  xlsWriteNumber($i, 0, 230);
  xlsWriteLabel($i, 1, "John");
  xlsWriteLabel($i, 2, "john@yahoo.com");
  $iPP;
}
xlsEOF();

this is my code
I"ve found some ways to put it up and it"s still garbled like this
what"s the problem?

clipboard.png


clipboard.png

Feb.11,2022

Excel the default code is GBK , so your Chinese should be converted to GBK to avoid garbled

.
Menu