PHP导出excel unicode(俄文字符)问题

PHP导出excel unicode(俄文字符)问题,php,unicode,export-to-excel,Php,Unicode,Export To Excel,我使用下面的代码使用php导出excel文件。对于英文文本,我没有发现任何问题。但是我发现了一些问题。我已附上我的代码 mysql_connect("localhost","USERNAME","PASSWORD"); mysql_select_db("DATABASE"); mysql_query("SET NAMES 'UTF8'"); // Get data records from table. $result=mysql_query("select * from usertbl ord

我使用下面的代码使用php导出excel文件。对于英文文本,我没有发现任何问题。但是我发现了一些问题。我已附上我的代码

mysql_connect("localhost","USERNAME","PASSWORD");
mysql_select_db("DATABASE");
mysql_query("SET NAMES 'UTF8'");
// Get data records from table.
$result=mysql_query("select * from usertbl order by user_id asc");

// Functions for export to excel.
function xlsBOF() {
   echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
   return;
 }
function xlsEOF() {
     echo pack("ss", 0x0A, 0x00);
     return;
 }
function xlsWriteNumber($Row, $Col, $Value) {
    echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
    echo pack("d", $Value);
    return;
 }
 function xlsWriteLabel($Row, $Col, $Value ) {
   $L = strlen($Value);
   echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
   echo $Value;
   return;
  }
  header("Pragma: public");
  header("Expires: 0");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header("Content-type: application/vnd.ms-excel;charset:UTF-8"); 
  header("Content-Type: application/force-download");
  header("Content-Type: application/octet-stream");
  header("Content-Type: application/download");
  header("Content-Disposition: attachment;filename=orderlist.xls ");
  header("Content-Transfer-Encoding: binary ");



  xlsBOF();

 /*
 Make a top line on your excel sheet at line 1 (starting at 0).
 The first number is the row number and the second number is the column, both are 
 start  at '0'*/

 xlsWriteLabel(0,0,"List of car company.");

 // Make column labels. (at line 3)
 xlsWriteLabel(2,0,"No.");
 xlsWriteLabel(2,1,"Nickname");

 $xlsRow = 3;

 // Put data records from mysql by while loop.
 while($row=mysql_fetch_array($result)){

   xlsWriteNumber($xlsRow,0,$row['user_id']);
   //$row['nickname']= iconv('UTF-8', 'SJIS', $row['NAME']);
   //$row['nickname'] = mb_convert_encoding($row['NAME'], 'UTF-16LE', 'UTF-8');
     xlsWriteLabel($xlsRow,1,$row['NAME']);

    $xlsRow++;
  }
 xlsEOF();
 exit();

XLS
文件格式非常复杂,我强烈建议不要编写自己的编写器实现


而是使用一种现有的实现,比如甚至选择写入
CSV
XLSX
格式。

我建议使用一个库,比如我自己的PHPExcel来编写Excel文件;但是您可以尝试设置一个代码页记录,告诉Excel您的字符串是UTF-8

function xlsCodepage($codepage) {
    $record    = 0x0042;    // Codepage Record identifier
    $length    = 0x0002;    // Number of bytes to follow

    $header    = pack('vv', $record, $length);
    $data      = pack('v',  $codepage);

    echo $header , $data;
}
并在调用xlsBOF()之后和写入任何数据之前调用xlsCodepage()函数

代码页的可能值(取决于您使用的字符集)为:


当我用俄语发送电子邮件时,你可以尝试使用我发现的mysqli_set_charset($connector,'utf8');帮助(其中connector-您的db连接变量是否设置为$connector=@mysqli_connect(db_主机、db_用户、db_密码、db_名称)-您必须首先定义这些内容)还需要仔细检查php文件本身是否以UTF-8编码,而没有BOM,并且所有表中的所有字段都是UTF-8。以下是有关mysqli_set_charset的更多信息:有没有办法向工作簿中添加新工作表并开始写入它?@Jeeva-你真的应该作为问题提问,而不是作为评论发布,以回应一个非常不同的问题question@Jeeva-createSheet()或addSheet()我已经把问题贴出来了,但是没有得到任何答案。我想知道如何使用xls格式而不是通过任何library@Jeeva-回答了你原来的问题-但你已经成为该组织的成员足够长的时间了,你知道背着一个不相关的问题不是推销你原来的问题的食物方式
367     ASCII       //  ASCII
437     CP437       //  OEM US
737     CP737       //  OEM Greek
775     CP775       //  OEM Baltic
850     CP850       //  OEM Latin I
852     CP852       //  OEM Latin II (Central European)
855     CP855       //  OEM Cyrillic
857     CP857       //  OEM Turkish
858     CP858       //  OEM Multilingual Latin I with Euro
860     CP860       //  OEM Portugese
861     CP861       //  OEM Icelandic
862     CP862       //  OEM Hebrew
863     CP863       //  OEM Canadian (French)
864     CP864       //  OEM Arabic
865     CP865       //  OEM Nordic
866     CP866       //  OEM Cyrillic (Russian)
869     CP869       //  OEM Greek (Modern)
874     CP874       //  ANSI Thai
932     CP932       //  ANSI Japanese Shift-JIS
936     CP936       //  ANSI Chinese Simplified GBK
949     CP949       //  ANSI Korean (Wansung)
950     CP950       //  ANSI Chinese Traditional BIG5
1200    UTF-16LE    //  UTF-16 (BIFF8)
1250    CP1250      //  ANSI Latin II (Central European)
1251    CP1251      //  ANSI Cyrillic
1252    CP1252      //  ANSI Latin I (BIFF4-BIFF7)
1253    CP1253      //  ANSI Greek
1254    CP1254      //  ANSI Turkish
1255    CP1255      //  ANSI Hebrew
1256    CP1256      //  ANSI Arabic
1257    CP1257      //  ANSI Baltic
1258    CP1258      //  ANSI Vietnamese
1361    CP1361      //  ANSI Korean (Johab)
10000   MAC         //  Apple Roman
65001   UTF-8       //  Unicode (UTF-8)