[英]UTF-8 encoding issue with laravel excel library
我在项目中使用laravel excel库将刀片文件导出为excel文件。 我的网站语言是波斯语,采用UTF-8编码。 我的问题是,当用户下载xls或csv文件时,该文件包含错误字符;如果另存为xlsx,则该文件什么也不显示。 这是我的刀片文件代码是:
<ul style="display: flex;justify-content: space-between;align-items: center;max-width: 800px; background-color:#ff008f;margin: 0 auto;text-align: center; color:#fff;min-width:500px;">
<li style="display: inline-block;padding:8px 10px;width: 35px;">ردیف</li>
<li style="display: inline-block;padding:8px 10px;width: 200px;">نام مشتری</li>
<li style="display: inline-block;padding:8px 10px;width: 200px;">شماره فاکتور</li>
<li style="display: inline-block;padding:8px 10px;width: 200px;">تعداد</li>
<li style="display: inline-block;padding:8px 10px;width: 200px;">تاریخ ثبت</li>
<li style="display: inline-block;padding:8px 10px;width: 200px;">ساعت ثبت</li>
<li style="display: inline-block;padding:8px 10px;width: 200px;">مبلغ کل</li>
</ul>
<div>
<?php
$i=1;
foreach($fields as $field){
?>
<ul style="display: flex;justify-content: space-between;align-items: center;max-width: 800px;margin: 0 auto;text-align: center; color:#111;min-width:500px;">
<li style="display: inline-block;width: 35px;padding:8px 10px;"><?php echo $i?></li>
<li style="display: inline-block;width: 200px;padding:8px 10px;"><?php echo $user->name?></li>
<li style="display: inline-block;width: 200px;padding:8px 10px;"><?php echo $field->refid?></li>
<li style="display: inline-block;width: 200px;padding:8px 10px;"><?php echo $count?></li>
<li style="display: inline-block;width: 200px;padding:8px 10px;"><?php echo $jDate?></li>
<li style="display: inline-block;width: 200px;padding:8px 10px;"><?php echo $field->time?></li>
<li style="display: inline-block;width: 200px;padding:8px 10px;"><?php echo $field->total_fee?></li>
</ul>
<?php
$i++;
$array = [$fields,$user,$count];
}
我导出到excel功能代码是:
public function exportXls(Request $request){
$fromDate = $request->input('fromDate');
$toDate=$request->input('toDate');
$fromDate = explode('/',$fromDate);
$fromGdate = jalali_to_gregorian($fromDate[2],$fromDate[1],$fromDate[0]);
$toDate = explode('/',$toDate);
$toGdate = jalali_to_gregorian($toDate[2],$toDate[1],$toDate[0]);
$fromTime = $request->input('fromTime');
$toTime = $request->input('toTime');
$data['fields'] = DB::table('z_orders')->whereBetween('date',array($fromGdate,$toGdate))->whereBetween('time',array($fromTime,$toTime))->get();
$data['without'] = false;
Excel::create('excelFile', function($excel) use($data) {
$excel->sheet('excelSheet', function($sheet) use($data) {
$sheet->loadView('admin.c-filter',$data);
});
})->download('xls');
return response()->json('YES');
}
将<meta charset="utf-8">
到视图或创建布局
<!DOCTYPE html>
<html lang="{{ \Lang::getLocale() }}">
<head>
<meta charset="utf-8">
</head>
<body>
@yield('content')
</body>
</html>
这对我有用:
http://www.maatwebsite.nl/laravel-excel/docs/blade
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.