Re: [請益] 存成 txt 檔
※ 引述《Joe8 (Beautiful Stranger)》之銘言:
: 謝謝提供經驗!
: 在下上網查了一下方法2:Spreadsheet_Excel_Writer
: 並取用了一個小範例程式,可是發生錯誤! 還請高手幫忙看一下,謝謝
: <?php
: require_once 'Spreadsheet/Excel/Writer.php';
: // We give the path to our file here
: $workbook = new Spreadsheet_Excel_Writer('test.xls');
: $worksheet =& $workbook->addWorksheet('My first worksheet');
: $worksheet->setInputEncoding('utf-8');
: $worksheet->write(0, 0, 'Name');
: $worksheet->write(0, 1, 'Age');
: $worksheet->write(1, 0, '剣');
: $worksheet->write(1, 1, 30);
: $worksheet->write(2, 0, 'Johann Schmidt');
: $worksheet->write(2, 1, 31);
: $worksheet->write(3, 0, 'Juan Herrera');
: $worksheet->write(3, 1, 32);
: // We still need to explicitly close the workbook
: $workbook->close();
: ?>
: 這樣在test.xls檔案中只有英文顯示得出來, 那個劍字變成問號... 請問該何解呢?
看你的情形應該是你的編輯器是 big5, 所以才會看不到.
幫你修一下:
<?php
require_once 'Spreadsheet/Excel/Writer.php';
// We give the path to our file here
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setVersion(8);
$workbook->send("test.xls");
$worksheet =& $workbook->addWorksheet('My first worksheet');
$worksheet->setInputEncoding('utf-8');
$worksheet->write(0, 0, 'Name');
$worksheet->write(0, 1, 'Age');
$worksheet->write(1, 0, iconv('big5','utf-8','劍'));
$worksheet->write(1, 1, 30);
$worksheet->write(2, 0, 'Johann Schmidt');
$worksheet->write(2, 1, 31);
$worksheet->write(3, 0, 'Juan Herrera');
$worksheet->write(3, 1, 32);
// We still need to explicitly close the workbook
$workbook->close();
?>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.190.50
→
07/09 19:28, , 1F
07/09 19:28, 1F
→
07/09 19:29, , 2F
07/09 19:29, 2F
→
07/09 19:30, , 3F
07/09 19:30, 3F
→
07/10 01:06, , 4F
07/10 01:06, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 7 之 7 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章