php - 从 Laravel 导出 Excel 而不安装任何库并获得奇怪的字符
问题描述
使用 Laravel 8
我的路线:
Route::get('socios/export', [SocioController::class, 'export'])->name('socios.export');
我的控制器方法:
public function export(Request $request)
{
$registros = User::socios()->get();
$content = view('socios.excel', compact('registros'));
$status = 200;
$headers = [
'Content-Type' => 'application/vnd.ms-excel; charset=utf-8',
'Content-Disposition' => 'attachment; filename="filename.xls"',
];
$response = response($content, $status, $headers);
return $response;
}
我的“socios.excel”视图:
<table>
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>...</th>
</tr>
</thead>
<tbody>
@foreach ($registros as $registro)
<tr>
<td>{{ $registro->id }}</td>
<td>{{ $registro->name }}</td>
<td>...</td>
</tr>
@endforeach
</tbody>
</table>
该文件导出正常,但像“Dirección”这样的字符串包含错误的字符:
我在内容类型标题中尝试了不同的字符集,但无法修复它。
一些帮助?
谢谢!
解决方案
推荐阅读
- share - 将私有托管区域关联到另一个帐户,(NotAuthorizedException)(退出状态 255)
- pandas - 如何最好地加入/合并列上的两个熊猫数据框(pandas.core.series.Series 和 pandas.core.frame.DataFrame)
- javascript - Vue没有应用样式类
- r - 关于 R 代码与舍入素数有关的问题
- php - symfony 3.4“驱动程序发生异常:SQLSTATE [HY000] [2002] php_network_getaddresses:getaddrinfo失败:名称或服务未知”
- c# - 并行运行测试和切换 iframe 时如何防止测试失败?
- c# - System.ArgumentNullException: '值不能为空。参数名称:key'
- windows - 在 Windows 10 重新启动到某个时间点期间黑屏
- javalite - 如何在 javalite db 迁移器中外部化用户名和密码?
- macos - applescript:如何复制真实文件而不是别名,但递归