我使用Laravel 5.2和maatwebsite / excel":" ~2.1.0包。现在,当我试图用英语导出PDF / XLS数据时,它的工作正常。但是,当我试图以其他语言导出数据时,我会收到乱码数据。
代码:
public function show(Request $request, $id)
{
//var_dump($request->all());
$type = $id;
$date = ($request->input('date') == '0' ? false : $request->input('date'));
$account = ($request->input('account') == '0' || !$request->has('account') ? false : $request->input('account'));
$device = ($request->input('device') == '0' ? false : $request->input('device'));
$search = ($request->input('search') == false || count($request->input('search')) == 0 ? false : $request->input('search'));
$client_id = $request->input('client_id');
$data = $this->getConversionsByDate($date, $account, $device,$search,$client_id);
$data = $this->parseData($data['conversions'],$type);
//echo "<pre>".print_r($this->parseData($data['conversions']),true)."</pre>";
return Excel::create('Poptin_conversions_data_'.Carbon::now()->toDateTimeString(), function($excel) use ($data) {
$excel->sheet('mySheet', function($sheet) use ($data){
$sheet->fromArray($data);
});
})->download($type);
}
protected function parseData($data,$type){
$conversions =[];
if ($type=='xls'){
foreach($data as $value){
$conversions[] = [
'created_at' =>$value->created_at,
'account_name' =>$value->account_name,
'poptin_name' =>$value->poptin_name,
'poptin_domain' =>$value->poptin_domain,
'visitor' =>trans('lang.'.$value->visitor),
'name' =>$value->name,
'phone' =>$value->phone,
'email' =>$value->email,
'message' =>$value->message,
'other_fields' => str_replace(array('a:','b:'),'',$value->other_fields),
'conversion_url' =>$value->conversion_url,
];
}
}else if ($type=='pdf'){
foreach($data as $value){
$conversions[] = [
'created_at' =>$value->created_at,
'name' =>(empty($value->name) ? '#' : $value->name),
'phone' =>(empty($value->phone) ? '#' : $value->phone),
'email' =>(empty($value->email) ? '#' : $value->email),
'message' =>(empty($value->message) ? '#' : $value->message),
'other_fields' =>(empty($value->other_fields) ? '#' : str_replace(array('a:','b:'),'',$value->other_fields)),
];
}
}
return $conversions;
}
查看&#34;名称&#34;细胞
它在刀片视图中的外观如何:
导出为PDF / XLS时的外观: