- 导出为中文字符串乱码的解决方案
vendor\encore\laravel-admin\src\Grid\Exporters\CsvExporter.php
在这个文件夹中修改:
public function export()
{
if ($this->callback) {
call_user_func($this->callback, $this);
}
print(chr(0xEF).chr(0xBB).chr(0xBF));
$response = function () {
$handle = fopen('php://output', 'w');
$titles = [];
$this->chunk(function ($collection) use ($handle, &$titles) {
Column::setOriginalGridModels($collection);
$original = $current = $collection->toArray();
$this->grid->getColumns()->map(function (Column $column) use (&$current) {
$current = $column->fill($current);
$this->grid->columnNames[] = $column->getName();
});
if (empty($titles)) {
fputcsv($handle, $titles = $this->getVisiableTitles());
}
foreach ($current as $index => $record) {
fputcsv($handle, $this->getVisiableFields($record, $original[$index]));
}
});
fclose($handle);
};
response()->stream($response, 200, $this->getHeaders())->send();
exit;
}
- 导出为科学计数法的解决方案
protected function getColumnValue(string $column, $value, $original)
{
if (!empty($this->columnUseOriginalValue)
&& in_array($column, $this->columnUseOriginalValue)) {
return $original;
}
if (isset($this->columnCallbacks[$column])) {
return $this->columnCallbacks[$column]($value, $original);
}
return $value . "\t";
}