Excel - 打开带有变音符号(+其他字符)的网页显示不正确

时间:2013-01-25 17:55:39

标签: php excel translation

我们有一个德国网站,用户输入的数据包括变音符号和其他德语字符。当我们朗读报告时,数据显示得很完美,但如果我们使用mime-type打开excel中的页面,它会打开文件,但德语字符没有正确显示。

示例如下:

ü显示为Ã

ö显示为ö

我们遇到了其他语言的问题,但这些已经通过在打开数据库后将其放入代码中来解决。

mysql_query( "set names 'utf8'" ) ;

我们如何让Excel显示这些字符。

以下是导致问题的代码

<?php ob_start(); ?>
<!DOCTYPE html PUBLIC " - //W3C//DTD XHTMKL 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1 -strict.dtd">

<html>
<head>
<title>Forum Report</title>
<link rel="shortcut icon" href="../templates/gk_music/favicon.ico" />

</head>
<body>

<form id="discussion" name="discussion" action="Discussion.php" method="post">

<div>
<?php

$message = $_REQUEST['signedin'] ;
if ($message != "YES")
{
header( 'Location: index.php?option=com_user&amp;view=login' ) ;
}

$ID = $_POST['ID'];
$excelselected = $_POST['excel'];
$print = $_POST['printit'];
if ($print == "yes")
{
    $excelselected  = "";
}

if ($excelselected == "excel")
{
<?php
header("Content-Type:  application/x-msexcel"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Disposition: attachment; filename=discussion.xls");
?>
    header(System.Text.UTF8Encoding.Default);
}

$row_count = 0; 
$today = date("F j, Y");
$reporttitle = "Forum Report";

include("../CommCultureIncludes/DB.php");
$link = @mysql_connect($host, $username, $password);
if (! $link){
    die("couldnt connect to mysql ".mysql_error()) ;
}

@mysql_select_db( $database)
or die ("Could Not Connect To Database : ".mysql_error() );

mysql_query( "set names 'utf8'" ) ;

if ($excelselected != "excel")
{
    include("../CommCultureIncludes/ReportHeaders.php");

    if ($print == "yes")
    {
        $divoptions = "display:none";
    }

    print "<div id='divoptions'  style='".$divoptions."' >";            
    print "<select class='dropdown'  name='selectBox' id='selectBox'          onchnge='OnChange(this.form.selectBox);'>";
    print "<option value ='0' >Select Discussion</option>";

    // set up dropdown  
    $result = mysql_query("SELECT DISTINCT thread, subject FROM ".$prefix."kunena_messages WHERE parent = 0 ORDER By Subject");
    while ($data = mysql_fetch_assoc($result))
    {               
        if ($ID == $data["thread"])
        {   
            print "<option selected value =".$data['thread'].">".$data['subject']."</option>";      
        }
        else
        {

            print "<option value   =".$data['thread'].">".$data['subject']."</option>";                 
        }
    }       
    print "</select>";      

    include("../CommCultureIncludes/ReportButtons.php");

    print "<br /><br />";
    print "</div>";
}

// display the results
$SQL = "select a.name user, a.description, b.subject, b.time, c.message, d.id,  d.username from ".$prefix."kunena_categories a, ".$prefix."kunena_messages b,  ".$prefix."kunena_messages_text c, ".$prefix."users d where a.id = b.catid and b.thread = "  .$ID. " and b.userid = d.id and b.id = c.mesid and b.hold = 0 ORDER BY b.time asc" ;
$result = mysql_query( $SQL);   
$num_rows = mysql_num_rows ($result);

print "<table class='detailtable'  width='80%' cellpadding='1' cellspacing='2'  border=\"0\">\n";


while ($a_row = mysql_fetch_assoc( $result ) ) {

    if ( $User != $a_row["user"])
    {
        print "<tr class='reportheaders' nowrap valign='top'>\n";   
        print "\t<td colspan='5' >Category : ".$a_row["user"]."</td>\n";
        print "</tr><tr>";
        print "\t<td colspan='3'  class='reportheaders' >&nbsp;&nbsp;&nbsp;&nbsp;Subject : ".$a_row["subject"]."</td>\n";
        Print "</tr>\n";
        $User = $a_row["user"];

        Print "<tr class='reportheaders'  valign='top'>\n";
        print "\t<td width='20%' >&nbsp;&nbsp;&nbsp;&nbsp;Date</td>\n";
        print "\t<td width='10%' >User Name</td>\n";
        print "\t<td colspan='3' >Message</td>\n";                  

    if ($excelselected == "excel")
    {
        // print full details for excel filtering

        // select all field types 
        $SQL = "select id, name FROM ".$prefix."community_fields where id not in (1,19,20,21) ORDER BY name" ;
        $fieldtypes = mysql_query($SQL);            

        While ($b_row = mysql_fetch_assoc($fieldtypes) ) 
            {   
            print "\t<td>".$b_row["name"]."</td>\n";
            }
        }
    }
    Print "</tr>\n";

    if  ($row_count % 2 != 0) 
    {
        print "<tr align='left'  valign='top' class='reportdetailseven' nowrap>";
    }
    else
    {
        print "<tr align='left' valign='top' class='reportdetailsodd' nowrap>";
    }

    $date = date('d-M-Y',$a_row["time"] );      
    $time = date('H:i:s',$a_row["time"] + 18000);

    print "\t<td width='20%' >&nbsp;&nbsp;&nbsp;&nbsp;".$date." ".$time."</td>\n";
    print "\t<td width='10%' >".$a_row["username"]."</td>\n";
    print "\t<td colspan='3' >".$a_row["message"]."</td>\n";

    if ($excelselected == "excel")
    {
        // print full details for excel filtering

        // for each field type get field value select all field types 
        $SQL = "select id, name FROM ".$prefix."community_fields where id not in (1,19,20,21) ORDER BY name" ;
        $fieldtypes = mysql_query($SQL);

        While ($b_row = mysql_fetch_assoc($fieldtypes) ) 
            {                   
                $fieldvalues =  mysql_query("SELECT *  FROM ".$prefix."community_fields_values a, ".$prefix."users b WHERE a.field_id = '".$b_row   ["id"]."' and a.user_id = b.id AND a.user_id = ".$a_row["id"]) ;                                
                $number  = mysql_num_rows($fieldvalues);

                if ($number == '0') 
                    {
                        print "\t<td>&nbsp;</td>\n";    
                    }
                    else
                    {
                        While ($c_row = mysql_fetch_assoc($fieldvalues) ) 
                        {
                        print "\t<td>".$c_row["value"]."</td>\n";   
                        }
                    }
            }           
    }

    Print "</tr>\n";

    $row_count++; 
}
print"</table>\n";

include("../CommCultureIncludes/HiddenFields.php");

mysql_close( $link );

?>

</div>

</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我们在页面的<head>部分需要以下元标记。

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