<table>
<thead>
<tr style="font-size: 16px;">
<th>approval_no</th>
<th>pnr</th>
<th>airline</th>
<th>cost</th>
<th>collected</th>
<th>due_date</th>
<th>time_limit</th>
<th>notes</th>
<th>approve_laststatus</th>
<th>customer</th>
<th>supplier</th>
<th>created_by</th>
<th>created_at</th>
<th>Assignee</th>
<th>Ticket Number</th>
<th>Created By</th>
<th>created_at</th>
<th>EMD Number</th>
<th>Created By</th>
<th>created_at</th>
<th>Invoice Number</th>
<th>Created By</th>
<th>created_at</th>
</tr>
</thead>
<tbody>
@foreach($approvals as $approval)
<tr>
<td>{{ $approval->approval_no }}</td>
<td>{{ $approval->pnr }}</td>
<td>{{ $approval->airline->airline }}</td>
<td>{{ $approval->cost }}</td>
<td>{{ $approval->collected }}</td>
<td>{{ date("m/d/Y", strtotime($approval->due_date))}}</td>
<td>{{ date("m/d/Y", strtotime($approval->time_limit))}}</td>
<td>{{ $approval->notes }}</td>
<td>{{ $approval->approve_laststatus}}</td>
<td>{{ $approval->customer->customer_name}}</td>
<td>{{ $approval->supplier->supplier_name}}</td>
<td>{{ $approval->creator->first_name}}</td>
<td>{{ date("m/d/Y", strtotime($approval->created_at))}}</td>
<td>{{$approval->assignee}}</td>
</tr>
@if(!empty($approval->tickets))
@foreach($approval->tickets as $ticket)
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<td>{{ $ticket->ticket_number }}</td>
<td>{{ $ticket->creator->first_name}}</td>
<td>{{ date("m/d/Y", strtotime($ticket->created_at))}}</td>
</tr>
@endforeach
@endif
@if(!empty($approval->emd))
@foreach($approval->emd as $emd)
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<td>{{ $emd->emd_number }}</td>
<td>{{ $emd->creator->first_name}}</td>
<td>{{ date("m/d/Y", strtotime($emd->created_at))}}</td>
</tr>
@endforeach
@endif
@if(!empty($approval->invoices))
@foreach($approval->invoices as $invoice)
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
<td>{{ $invoice->invoice_number }}</td>
<td>{{ $invoice->creator->first_name}}</td>
<td>{{ date("m/d/Y", strtotime($invoice->created_at))}}</td>
</tr>
@endforeach
@endif
@endforeach
</tbody>
</table>
我使用 laravel 导出到 excel 加载关系数据,这是我用来在 Excel 工作表中显示数据的当前代码,我使用 laravel 视图来获取输出。附件是输出,嵌套数据打印在一行向下。 相关数据以相同颜色着色。 如何让相关数据在同一行开始?
要使相关数据在同一行开始,您可以修改 HTML 表格的结构。目前,主审批行中的每个相关数据(票据、emd、发票)都有单独的行。相反,您可以将相关数据的单元格合并到单个单元格中,并使用 colspan 跨越多个列。
<table>
<thead>
<tr style="font-size: 16px;">
<!-- Header columns -->
</tr>
</thead>
<tbody>
@foreach($approvals as $approval)
<tr>
<!-- Main approval data -->
</tr>
@if(!empty($approval->tickets))
<tr>
<td colspan="12">
<table>
<thead>
<tr>
<!-- Header columns for tickets -->
</tr>
</thead>
<tbody>
@foreach($approval->tickets as $ticket)
<tr>
<!-- Ticket data -->
</tr>
@endforeach
</tbody>
</table>
</td>
</tr>
@endif
@if(!empty($approval->emd))
<tr>
<td colspan="12">
<table>
<thead>
<tr>
<!-- Header columns for emd -->
</tr>
</thead>
<tbody>
@foreach($approval->emd as $emd)
<tr>
<!-- EMD data -->
</tr>
@endforeach
</tbody>
</table>
</td>
</tr>
@endif
@if(!empty($approval->invoices))
<tr>
<td colspan="12">
<table>
<thead>
<tr>
<!-- Header columns for invoices -->
</tr>
</thead>
<tbody>
@foreach($approval->invoices as $invoice)
<tr>
<!-- Invoice data -->
</tr>
@endforeach
</tbody>
</table>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>