douwen7516 2016-03-14 12:20
浏览 51

PHP导出到csv,编码为excel

i've written a simple php application on a xampp enviroment on my windows desktop. Its a simple output of an html table into a csv file. and it works correctly.

Now i moved the Application to a linux apache server. Now the CSV export also works correctly but when i open it with excel(it's correctly displayed in Notepad) the german umlauts are not displayed. How i said, this worked well on my xampp server. Do you have any idea where my mistake is?

Php default_chartype="utf-8"

<?php

include('func/connect.php');

header("Content-type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=export".time().".csv; charset=utf-8");
header('Content-Transfer-Encoding: binary');
header("Pragma: no-cache");
header("Expires: 0");



$date = explode(" ", $_GET['startDate']);
$monthname= $date[0];
$month=1;
$year= $date[1];
$monthArray = array("January","February","March","April","May","June","July","August","September","October","November","December");

for($i=1;$i<=$monthArray;$i++){
     if($monthArray[$i]==$monthname){
        $month++;
        break;
    }
    else{
        $month++;
    }
}

echo "PNR; Vorname; Nachname; Betrag ";

$q = "SELECT mitarbeiter.ID,mitarbeiter.Vorname,mitarbeiter.Nachname, SUM(Betrag) as Betrag FROM mitarbeiter INNER JOIN transaktionen on mitarbeiter.ID= transaktionen.PNR WHERE obsolete IS NULL AND transaktionen.Date BETWEEN '".$year."-".$month."-01' AND '".$year."-".$month."-".cal_days_in_month(CAL_GREGORIAN, $month, $year)."' GROUP BY ID";
$result = mysqli_query($mysqli, $q) or die ('Unable to execute query. '. mysqli_error($q));

while($query = mysqli_fetch_assoc($result)) {
    echo '="'.$query["ID"].'";'. $query["Vorname"].";". $query["Nachname"].";". number_format($query["Betrag"], 2, ',', '')."
";
}

?>

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题