PEAR Spreadsheet Excel Writer创建Excel文档时中文乱码的解决方法

不指定
2008-9-9 23:19 by:果面 PC应用 » 网络应用 本站原创 | |
<?php
require 'Spreadsheet/Excel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer('multi-worksheet-demo.xls'); // 初始化类
//$workbook->send('multi-worksheet-demo.xls'); // 发送 Excel 文件名供下载
$n=$_POST['N'];
$h=$_POST&#91;'H'];
$t=$_POST['T'];
$c=$_POST['C'];
$worksheet =& $workbook->addWorksheet('sheet-1'); // 加入一个工作表 sheet-1
$data = array(
    array($n, $h, $t,$c),
    array("中文测试", "中文测试", "中文测试","中文测试")
);
for ($row = 0; $row < count($data); $row ++) {
    for ($col = 0; $col < count($data[0]); $col ++) {
        $worksheet->writeString($row, $col, iconv("UTF-8","GB2312",$data[$row][$col])); // 写入数据
    }
}
$workbook->close(); // 完成下载
?>
评论(0) 引用(0) 阅读(3251)