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

所以我在刀片视图文件上有一个表,我已成功将其导出到 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');


繁花如伊
浏览 78回答 1
1回答

12345678_0001

我不知道我是否正确理解了一切,但你为什么不做这样的事情:$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 时,您只需不传递此变量并且不会呈现该列。
打开App,查看更多内容
随时随地看视频慕课网APP