0

我们有一个德语网站,用户输入的数据包括变音符号和其他德语字符。当我们朗读一份报告时,数据会完美显示,但如果我们随后使用 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>
4

1 回答 1

0

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

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

富有的

于 2015-10-13T09:45:37.667 回答