可能存在类似的问题,但很遗憾地说我找不到。所以让我问我的问题。
我具有PHP功能,可从浏览器下载CSV文件,如下所示:
function outputCSV($data, $file_name = 'file.csv') {
header('Content-Encoding: UTF-8');
# output headers so that the file is downloaded rather than displayed
header('Content-type: text/csv; charset=utf-8');
header("Content-Disposition: attachment; filename=$file_name");
header('Content-Transfer-Encoding: binary');
# Disable caching - HTTP 1.1
header("Cache-Control: no-cache, no-store, must-revalidate");
# Disable caching - HTTP 1.0
header("Pragma: no-cache");
# Disable caching - Proxies
header("Expires: 0");
# Start the ouput
$output = fopen("php://output", "w");
fputs($output, "\xEF\xBB\xBF"); // UTF-8 BOM !!!!!
# Then loop through the rows
foreach ($data as $row) {
# Add the rows to the body
fputcsv($output, $row); // here you can change delimiter/enclosure
}
# Close the stream off
fclose($output);
}
下载文件后,使用Windows 10 Excel应用程序打开时,将连接日语字符。但是可以使用文本编辑器(如NotePad ++)正确查看。
对此有帮助吗?
谢谢。