酷!學園

技術討論區 => 網頁技術 => 主題作者是: tonyvan123 於 2015-10-27 17:38

主題: 請問ExcelWriterXML如何寫入中文
作者: tonyvan1232015-10-27 17:38
經過1個星期的測試,中文問題仍無解
主題: 程式碼如下
作者: tonyvan1232015-10-28 11:33
<?php
/**
 * Example page for how to use the Excel Writer XML
 * @package ExcelWriterXML
 * @subpackage examples
 * @filesource
 */

/**
 * Include the required Class file
 */
include('ExcelWriterXML.php');

/**
 * @source
 */
$xml = new ExcelWriterXML;
$xml->docAuthor('Robert F Greer');
$xml->overwriteFile(true);

$iHeaderFormat1 = $xml->addStyle('StyleHeader');
$iHeaderFormat1->alignHorizontal("Left");
$iHeaderFormat1->alignVertical("Center");

$iTextFormat1 = $xml->addStyle('Text1');
$iTextFormat1->alignHorizontal("Left");
$iTextFormat1->alignVertical("Center");
 
$iNUMFormat1 = $xml->addStyle('Number1');
$iNUMFormat1->alignHorizontal("Right");
$iNUMFormat1->alignVertical("Center"); 
$iNUMFormat1->numberFormat('#,##0.00'); 


$iDateFormat1 = $xml->addStyle("DateFormat1");
$iDateFormat1->alignHorizontal("Left");
$iDateFormat1->alignVertical("Center");
$iDateFormat1->numberFormatDatetime('yyyy/mm/ddThh:mm:ss');
 
$sheet1 = $xml->addSheet('My Sheet');

$sheet1->writeString(1,1,'標題一','StyleHeader');
$sheet1->writeString(1,2,'Number','StyleHeader');
$sheet1->writeString(1,3,'DateTime','StyleHeader');

$sheet1->writeString(2,1,'Test String','Text1');
$sheet1->writeNumber(2,2,1234.32,'Number1');
$sheet1->writeDateTime(2,3,'2015/10/23 11:52:12','DateFormat1');

$xml->sendHeaders();
$xml->writeData('MyFile1.xml');
?>
主題: Re: 請問ExcelWriterXML如何寫入中文
作者: tonyvan1232015-10-28 17:18
自己解答
把 ExcelWriterXML.php中的xml head 改掉即可

修改前$xml = '<?xml version="1.0"  ?>'

修改後$xml = '<?xml version="1.0"  encoding="BIG5" ?>'