【问题标题】:UTF-8 encoding issue with laravel excel librarylaravel excel库的UTF-8编码问题
【发布时间】:2015-11-17 06:33:47
【问题描述】:

我在项目中使用 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 函数。 这是这个图书馆给我的照片:

【问题讨论】:

  • 谁能帮帮我?

标签: php excel laravel utf-8 laravel-excel


【解决方案1】:

&lt;meta charset="utf-8"&gt; 添加到您的视图或创建布局

<!DOCTYPE html>
<html lang="{{ \Lang::getLocale() }}">
<head>
    <meta charset="utf-8">
</head>
<body>
    @yield('content')
</body>
</html>

【讨论】:

    【解决方案2】:

    这对我有用:

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

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    

    【讨论】:

      猜你喜欢
      • 2010-12-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-12
      • 2017-12-22
      • 2011-11-08
      相关资源
      最近更新 更多