繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM