输出到excel.csv提供了奇怪的效果

时间:2018-09-18 11:23:06

标签: php excel slim-3

我似乎无法让ÆØÅ给我正确的字符。

如果我打开Excel,然后从数据导入并选择UTF-8,它将正确显示。但是我不能要求用户打开excel并执行此操作,那么如何使Excel第一次正确打开文件?

//Give our CSV file a name.
        $csvFileName = 'example.csv';

        //Open file pointer.        
        $fp = fopen('php://output', 'w');

        //Loop through the associative array.
        foreach($sortedData as $row){
            //Write the row to the CSV file.                        
            fputcsv($fp, $row,";");
        }

        //Finally, close the file pointer.
        fclose($fp);

        $response = $response->withHeader('Content-Type', 'text/csv; charset=utf-8');
        $response = $response->withHeader('Content-Disposition', 'attachment; filename="file.csv"');

        $stream = fopen('php://memory', 'r+');      

        return $response->withBody(new \Slim\Http\Stream($stream));

0 个答案:

没有答案