开发者

HTML Table to *.xls encoding problems

My export script:

if($_POST){
    $file = 'FKDB_XLS';
    $filename = $file."_".date("Y-m-d_H-i",time()); 
    header("Content-type: application/vnd.ms-excel; charset=utf-8"); // dunno if the charset does anything for this application type..
    header("Content-Disposition: attachment; filename=$filename");
    echo stripslash开发者_如何转开发es($_SESSION['item']); unset($_SESSION['item']);
    exit;
}

Basicly, it just turns HTML ($_SESSION['item'] as <table>{rows}</table>) into *.xls and allows Excel to draw tables from that data, as most of you know, probably.

The problem is, when opened in Excel, everything's OK, except... all the values are written incorrectly, with all the Ä, ņŠand so on instead of 'Ā' or so, again.

What should I do to prevent that?

Thanks in advance!


If you're writing HTML markup for import into excel, then you need to ensure that you're setting the appropriate meta tags in the HTML header. specifying charset in the Content type will have absolutely no effect at all. If you're simply writing a table, then wrap it in HTML/HEAD/BODY, etc so that you can set the HEAD meta tags.

I still don't understand why people write HTML and give the file an xls extension when it's so easy to create a real Excel file!


Add this to your HTML table, so Excel will read it on the fly:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜