Skip to content

Commit

Permalink
Merge pull request #5447 from keller31/patch-1
Browse files Browse the repository at this point in the history
BOM 头应该放到文件头部输出
  • Loading branch information
jxlwqq authored Oct 23, 2021
2 parents a9f9c58 + bc5489e commit 39bb797
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Grid/Exporters/CsvExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function export()
$response = function () {
$handle = fopen('php://output', 'w');
$titles = [];

fwrite($handle, chr(0xEF).chr(0xBB).chr(0xBF)); //导出的CSV文件是无BOM编码UTF-8,而我们通常使用UTF-8编码格式都是有BOM的。所以添加BOM于CSV中
$this->chunk(function ($collection) use ($handle, &$titles) {
Column::setOriginalGridModels($collection);

Expand All @@ -170,7 +170,7 @@ public function export()
$current = $column->fill($current);
$this->grid->columnNames[] = $column->getName();
});
fwrite($handle, chr(0xEF).chr(0xBB).chr(0xBF)); //导出的CSV文件是无BOM编码UTF-8,而我们通常使用UTF-8编码格式都是有BOM的。所以添加BOM于CSV中

// Write title
if (empty($titles)) {
fputcsv($handle, $titles = $this->getVisiableTitles());
Expand Down

0 comments on commit 39bb797

Please sign in to comment.