我有从Maatwebsite创建电子表格的代码,我使用Laravel 5.7,
我的代码描述如下:
export.blade.php
<table>
<thead>
<tr><th colspan="{{ $colspan }}">{{ $monthText }}</th></tr>
<tr>
@foreach($theader as $thead)
@if($thead == "Email")
@continue
@endif
<th>{{ $thead }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($records as $record)
<tr>
@foreach($record as $key=>$value)
@if($key == "Email")
@continue
@endif
<td>{{ $value }}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
<table>
<thead>
<tr><th colspan="{{ $colspan }}">Month to Date (MTD)</th></tr>
<tr>
@foreach($theader as $thead)
@if($thead == "Email")
@continue
@endif
<th>{{ $thead }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($records as $record)
<tr>
@foreach($record as $key=>$value)
@if($key == "Email")
@continue
@endif
<td>{{ $value }}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
重复表仅用于测试使用此代码完成导出后在Excel中的显示方式
class TopFiveExport implements FromView, WithTitle
{
protected $data;
protected $sheetTitle;
function __construct($result,$parameters)
{
$this->sheetTitle = $parameters['title'];
$this->data['theader'] = array_keys($result[0]);
$this->data['records'] = $result;
$this->data['colspan'] = $parameters['colspan'];
$this->data['monthText'] = $parameters['monthText'];
}
public function view(): View
{
return view('exports.backoffice.top5',$this->data);
}
public function title(): string
{
return $this->sheetTitle;
}
}
关于如何使excel并排导出表的任何想法,目前,我将两个表彼此并排放置,我希望它们并排放置。