Laravel Excel如何将视图加载到特定的行或单元格? [英] Laravel Excel how to load a view to specific row or cell?

查看:251
本文介绍了Laravel Excel如何将视图加载到特定的行或单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel Excel,我想加载一个视图文件并将其设置为特定行. laravel excel可以做到吗? 下面是将视图加载到工作表中的代码:

I'm using Laravel Excel, I want to load a view file and set it to specific row. Is it possible to do it with laravel excel? bellow is the code for loading view in to the sheet:

Excel::create('New file', function($excel) {

    $excel->sheet('New sheet', function($sheet) {

       $sheet->loadView('folder.view');

    });

});

推荐答案

这次似乎软件包不提供我了,但是也许您可以这样做.

It seems like the package doesn't offer that I this time but maybe you could do something like this.

  • 创建一个包装视图,您可以将一些参数传递给该包装视图,例如目标行号,列号和要包含的内部视图.

  • Create a wrapping view that you can pass some parameters to, such as a target row number, column number and inner view to include.

Excel::create('New file', function($excel) {

    $excel->sheet('New sheet', function($sheet) {

       $sheet->loadView('path.to.wrapping.view')->with(["targetRow"=>5,"targetCol"=>10,"targetView"=>"path.to.target.view"]);

    });

})->download();

  • 根据提供给包装视图的参数动态生成表.视图的内容可能是这样的.

  • Dynamically generate a table based on the parameters provided to the wrapping view. The content of the view could be something like this.

    @if(isset($targetRow) && isset($targetCol)) table tag @for ($row = 1; $row <= $targetRow + 1; $row++) tr tag @for ($col = 1; $col <= $targetCol + 1; $col++) td tag @if($row == $targetRow && $col == $targetCol) @include($targetView) @endif close td tag @endfor close tr tag @endfor close table tag @endif

    @if(isset($targetRow) && isset($targetCol)) table tag @for ($row = 1; $row <= $targetRow + 1; $row++) tr tag @for ($col = 1; $col <= $targetCol + 1; $col++) td tag @if($row == $targetRow && $col == $targetCol) @include($targetView) @endif close td tag @endfor close tr tag @endfor close table tag @endif

    这篇关于Laravel Excel如何将视图加载到特定的行或单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆