Reputation: 39
I'm having a trouble that I can't export japanese texts to excel (xls).
I used the following codes:
header('Content-type: application/ms-excel;charset=UTF-8');
header('Content-Disposition: attachment; filename='.$filename);
header("Pragma: no-cache");
echo $contents;
But in the excel file, the text changed to funny characters like this:
é™?定ç‰? ã?¨ã??ã?¯ã??ã?£ã?†ã?ªã?¢å??犬ã?®ã?Œæ??ã?
’è??ã??ã?Ÿã?†ã?£ã??ã??ã??ã?? ï??
Currently, I'm using hostingmanager and I tried on the different server using the same codes and there's no problem.
What could be the problem. Because of the PHP version?? Please help me.
Upvotes: 3
Views: 6986
Reputation:
try this
<form action="itemexcel.php" method="post"
onsubmit='$("#datatodisplay").val( $("<div>").append( $("#ReportTable")
.eq(0).clone()).html() )'>
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 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'];
?>
Upvotes: 1
Reputation: 17360
header("Content-type: application/vnd.ms-excel;charset=UTF-8");
header("Content-Disposition: attachment; filename=\"download.xlsx");
header("Cache-control: private");
Upvotes: 0