0

ドイツ語の Web サイトがあり、ユーザーが入力したデータには、ウムラウトやその他のドイツ語の文字が含まれています。レポートを作成すると、データは完全に表示されますが、MIME タイプを使用して 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 に答える