本文介绍了PHP导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了无法将日语文本导出到excel(xls)的麻烦.

I'm having a trouble that I can't export japanese texts to excel (xls).

我使用了以下代码:

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

但是在excel文件中,文本更改为有趣的字符,如下所示:

But in the excel file, the text changed to funny characters like this:

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

’â€??£??ã?ŸÃ??††£?£££??ã??ã??ã?? Ã??

’è??ã??ã?Ÿã?†ã?£ã??ã??ã??ã?? ï??

当前,我正在使用hostingmanager,并且我尝试使用相同的代码在不同的服务器上进行操作,

Currently, I'm using hostingmanager and I tried on the different server using the same codes and there's no problem.

可能是问题所在.因为是PHP版本?请帮助我.

What could be the problem. Because of the PHP version??Please help me.

推荐答案

尝试一下

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

div或表我们要使用的div或表应该是id ="ReportTable"

div or table what ever we want to use div or table should be 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页面

itemexcel.php page

<?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'];
?>

这篇关于PHP导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 06:15