Php CSV导出UTF8编码导致不正确的Excel格式

时间:2016-01-16 10:12:29

标签: php excel csv utf-8

我累了做csv导出。我需要使用普通标题

在表格中使用两种语言(泰米尔语和英语)
            $exclude = array();

        $args = array(
            'order'          => 'ASC',
            'post_type'      => 'attachment',
            'post_mime_type' => 'image',
            'post_parent'    => $pid,
            'numberposts'    => -1,
            'post_status'    => null,
        );

        $attachments = get_posts($args);

        foreach($attachments as $att) $exclude[] = $att->ID;

        $args = array(
            'order'          => 'ASC',
            'post_type'      => 'attachment',
            'post_parent'    => $pid,
            'post_author'    => $uid,
            'ID'             => $pkey,
            'exclude'    => $exclude,
            'numberposts'    => -1,
            'post_status'    => null,
        );
        $attachments = get_posts($args);



        if(count($attachments) == 0) echo __('No project files.','ProjectTheme');

                    foreach($attachments as $at) {
                     if($at->post_author == $user->ID) {
                       if($at->post_parent == $row->pid) {
                           if($at->post_date == $at['max(post_date)']) {
                          $fileName = wp_get_attachment_url($at->ID);
                          echo '<div>'. mp3j_put('[mp3j track="' . $fileName . '" flip="y"]').'</div><br>';
                                         }}}}
                                          ;

这导致显示的泰米尔语字符出现问题。但是excel的格式很好。所以我使用UTF8编码来显示泰米尔语字符,如下所示。

    $now = gmdate("D, d M Y H:i:s");
    header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
    header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
    header("Last-Modified: {$now} GMT");
    header ( 'Content-Type: application/vnd.ms-excel') ;
    header("Content-Disposition: attachment;filename={$filename}");
    header("Content-Transfer-Encoding: binary");
    echo $content;

这有助于字符和两种语言现在正常显示但生成的csv的格式被中断。一切都显示在一列中。无论如何要解决这个问题吗?

0 个答案:

没有答案
相关问题