1

我在项目中使用 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');
 }

我使用 ajax 请求来调用exportXls函数。这是这个图书馆给我的照片: 我的刀片文件中有链接下载 excel 文件,我给了那个英文名称“excel”,在这里是正确的,但其他人没有。

4

2 回答 2

0

添加<meta charset="utf-8">到您的视图或创建布局

<!DOCTYPE html>
<html lang="{{ \Lang::getLocale() }}">
<head>
    <meta charset="utf-8">
</head>
<body>
    @yield('content')
</body>
</html>
于 2015-11-19T00:30:10.860 回答
0

这对我有用:

http://www.maatwebsite.nl/laravel-excel/docs/blade

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
于 2016-10-28T07:13:39.883 回答