[英]How Export only specific columns from Laravel Blade table view to Ecxel file?
所以我有一個關於刀片視圖文件的表格,我已經成功地將它導出到 excel 文件中。 現在我想在不導出“操作”列的情況下導出。我該怎么做?
我在下面附上了我的代碼和刀片文件,它工作得很好。 我只想導出除操作列之外的所有內容,因為它包含用於數據庫操作的按鈕
這是我的出口 CLASS 代碼:
public function view(): View
{
return view ('ims.view_inventory_history_table', [
'data' => inbound_history::all()
]);
}
public function headings(): array
{
return [
'ID',
'Warehouse',
'SKU',
'Child SKU',
'Units',
'Invoice No.',
'Container No.',
'Entry Date'
];}
/**
* @return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$cellRange = 'A1:W1'; // All headers
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
},
];
}}
這是我的 CONTROLLER FUNCTION:
public function export_view()
{
return Excel::download(new inboundHistory(), 'inboundHistory.xlsx');
}
這是我的路線:
Route::Get('inbound_history/export_view' ,'imsController@export_view')->name('inbound_history.export_view');
這是我的刀片表視圖:
<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th style="width:5%">ID</th>
<th>Warehouse</th>
<th>SKU</th>
<th>Child SKU</th>
<th>Cases</th>
<th>Units</th>
<th>Invoice No.</th>
<th>Container No.</th>
<th>Entry Date</th>
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
</tr>
</thead>
<tbody>
@foreach ($data as $row)
<tr>
<td>{{$row['id']}}</td>
<td>{{$row['warehouse']}}</td>
<td>{{$row['sku_parent']}}</td>
<td>{{$row['sku_child']}}</td>
<td>{{$row['total_cases']}}</td>
<td>{{$row['total_units']}}</td>
<td>{{$row['invoice_no']}}</td>
<td>{{$row['container_no']}}</td>
<td>{{$row['date_rec']}}</td>
<td class="td-actions text-right">
{{-- <a rel="tooltip" class="btn btn-success btn-link" href="{{action('imsController@edit',$row['id'])}}">
<i class="material-icons">edit</i></a> --}}
<a rel="tooltip" class="btn btn-danger btn-link" href="{{action('imsController@destroy',$row['id'])}}" onclick = "if (! confirm('Confirm: Press OK to delete the Entry.')) { return false; }"style="color: red;">
<i class="material-icons">close</i></a>
</td>
</tr>
@endforeach
</tbody>
我不知道我是否得到了正確的一切,但你為什么不做這樣的事情:
當您想為用戶創建視圖時,將附加變量傳遞給您的刀片模板,例如$isView
。
在您的 Blade.php 模板中,您可以執行以下操作:
@isset($isView)
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
@endisset
// do the same @isset test for the corresponding <td> element
當您想將其渲染為 excel 時,您只需不傳遞此變量並且不會渲染該列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.