3

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.

6
  • 1
    Where do you get the contents of $contents from? Commented Nov 30, 2012 at 5:06
  • I get the variables from the data base and put all into that variable($contents). $contents .= order_id"."\t"."$fname"."\t"."$lname"."\t"."$email"."\t"; Commented Nov 30, 2012 at 6:26
  • Have you considered sending an actual excel payload/file, instead of just CSV disguised as it? Commented Nov 30, 2012 at 7:34
  • possible duplicate of "Warning: Headers already sent" in PHP Commented Nov 30, 2012 at 7:34
  • The same database on both servers? Commented Dec 1, 2012 at 19:40

2 Answers 2

1

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'];
?>
Sign up to request clarification or add additional context in comments.

Comments

0
header("Content-type: application/vnd.ms-excel;charset=UTF-8"); 
header("Content-Disposition: attachment; filename=\"download.xlsx");
header("Cache-control: private");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.