Laravel-excel: 如果任何/所有工作表都实现了 FromView,则多张工作表不起作用

创建于 2018-03-26  ·  3评论  ·  资料来源: Maatwebsite/Laravel-Excel

先决条件

  • [ ] 能够重现代码之外的行为,该问题与 Laravel Excel 隔离。
  • [X] 检查您的问题是否尚未提交。
  • [X] 检查是否没有提交解决此问题的 PR。

版本

  • PHP 版本:7.2
  • Laravel 版本:5.5
  • 包版本:3.0.1

描述

如果任何/所有工作表都是 FromView,则多张工作表不起作用

  • 所有实现 FromView 的工作表(不工作)
  • 1 张 FromView 和另一个实现 FromCollection (不工作)
  • 所有没有实现 FromView 的工作表(工作正常)

重现步骤(附上我的代码)

`
类 FormatReportExport 实现了 WithMultipleSheets、Responsable
{
使用可出口;

protected $reports;
protected $summary;

public function __construct($summary, $reports)
{
    $this->summary = $summary;
    $this->reports = $reports;
}

public function sheets(): array
{
    $sheets = [];

    $sheets[] = new ReportSummaryExport($this->summary);
    $sheets[] = new ReportExport($this->reports);

    return $sheets;
}

}
`

`
类 ReportSummaryExport 实现 FromCollection、WithTitle
{
受保护的 $summary;

public function __construct($summary)
{
    $this->summary = $summary;
}


public function collection()
{
    return User::get();
}

/**
 * <strong i="34">@return</strong> string
 */
public function title(): string
{
    return 'Summary';
}

}`

`类 ReportExport 实现了 FromView、WithTitle
{
受保护的 $reports;

public function __construct($reports)
{
    $this->reports = $reports;
}

public function view(): View
{
    return view('export.report.list', [
        'title' => $this->title(),
        'reports' => $this->reports
    ]);
}

/**
 * <strong i="41">@return</strong> string
 */
public function title(): string
{
    return 'Checklists';
}

}`

list.blade.php
`@extends('layouts.export', ['title' => $title])

@section('内容')

@foreach($reports as $report)@endforeach
创建日期
{{ $report['created_at'] }}

@endsection`

预期行为:

基于视图的具有多个工作表的 Excel 文件。

实际行为:

image

最有用的评论

所有3条评论

感谢您提交门票。 我们将在有可用资源时尽快获取它(如我们的支持指南 (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/support) 中所述)。

很可能会被 #1590 解决

此页面是否有帮助?
0 / 5 - 0 等级