为了账号安全,请及时绑定邮箱和手机立即绑定

如何仅将 Laravel Blade 表视图中的特定列导出到 Ecxel 文件?

如何仅将 Laravel Blade 表视图中的特定列导出到 Ecxel 文件?

PHP
繁花如伊 2023-08-11 16:51:33
所以我在刀片视图文件上有一个表,我已成功将其导出到 Excel 文件中。现在我想导出而不导出“操作”列。我该怎么做?我在下面附上了我的代码和刀片文件,它工作得很好。我只想导出除操作列之外的所有内容,因为它包含用于数据库操作的按钮这是我的出口类别代码: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);        },    ];}}这是我的控制器功能: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');
查看完整描述

1 回答

?
12345678_0001

TA贡献1802条经验 获得超5个赞

我不知道我是否正确理解了一切,但你为什么不做这样的事情:


$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 时,您只需不传递此变量并且不会呈现该列。


查看完整回答
反对 回复 2023-08-11
  • 1 回答
  • 0 关注
  • 75 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信