3

日本語のテキストをエクセル(xls)に書き出せず困っています。

次のコードを使用しました。

header('Content-type: application/ms-excel;charset=UTF-8');
header('Content-Disposition: attachment; filename='.$filename); 
header("Pragma: no-cache");     
echo $contents;

しかし、Excel ファイルでは、テキストが次のようなおかしな文字に変わりました。

é™?定ç‰? ã?¨ã??ã?¯ã??ã?£ã?†ã?ªã?¢å??犬ã?®ã?Œæ??ã? 

â'ã??ã£??ã£?âŸã?â†ã£?â£ã£??ã£??ã£??ã?? ??

現在、hostingmanager を使用しており、同じコードを使用して別のサーバーで試してみましたが、問題はありません。

何が問題になる可能性があります。PHPのバージョンのせい?? 私を助けてください。

4

2 に答える 2

1

これを試して

<form action="itemexcel.php" method="post" 
onsubmit='$("#datatodisplay").val( $("<div>").append( $("#ReportTable")
.eq(0).clone()).html() )'>

div または table 使用する div または table は id="ReportTable" にする必要があります

<table id="ReportTable" width="781" border="2"> Or <div id id="ReportTable">
<tr>
<td><input type="hidden" id="datatodisplay" name="datatodisplay"></td>
<td><input class="bg" type="submit" value="Export To Excel"></td>
</tr></table></div>

<input type="hidden" id="datatodisplay" name="datatodisplay">
<input class="bg" type="submit" value="Export To Excel">

itemexcel.php ページ

<?php
header('Content-Type: application/force-download');
header('Content-disposition: attachment; filename=itemcode.xls');
// Fix for crappy IE bug in download.
header("Pragma: ");
header("Cache-Control: ");
echo $_REQUEST['datatodisplay'];
?>
于 2013-04-01T20:53:18.220 に答える
0
header("Content-type: application/vnd.ms-excel;charset=UTF-8"); 
header("Content-Disposition: attachment; filename=\"download.xlsx");
header("Cache-control: private");
于 2012-11-30T06:30:18.387 に答える