Re: [請益] 存成 txt 檔

看板PHP作者 (總是不知所措)時間17年前 (2008/07/09 18:14), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串7/7 (看更多)
※ 引述《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
如果是因為編碼問題,不需用到iconv,將檔案儲存為
07/09 19:28, 1F

07/09 19:29, , 2F
UTF-8編碼,應該就可以了吧?
07/09 19:29, 2F

07/09 19:30, , 3F
附帶一提,其實原文中的「劍」是日文 XD
07/09 19:30, 3F

07/10 01:06, , 4F
推樓上, 因為我也看不到那個 劍 字.
07/10 01:06, 4F
文章代碼(AID): #18T8zo52 (PHP)
討論串 (同標題文章)
文章代碼(AID): #18T8zo52 (PHP)