php – Laravel Excel如何将视图加载到特定的行或单元格?

前端之家收集整理的这篇文章主要介绍了php – Laravel Excel如何将视图加载到特定的行或单元格?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Laravel Excel,我想加载一个视图文件并将其设置为特定的行.用laravel excel可以做到吗?
bellow是用于将视图加载到工作表的代码
  1. Excel::create('New file',function($excel) {
  2.  
  3. $excel->sheet('New sheet',function($sheet) {
  4.  
  5. $sheet->loadView('folder.view');
  6.  
  7. });
  8.  
  9. });
看起来这次包裹不提供我,但也许你可以做这样的事情.

>创建一个可以传递一些参数的包装视图,例如目标行号,列号和要包括的内部视图.

  1. Excel::create('New file',function($sheet) {
  2.  
  3. $sheet->loadView('path.to.wrapping.view')->with(["targetRow"=>5,"targetCol"=>10,"targetView"=>"path.to.target.view"]);
  4.  
  5. });
  6.  
  7. })->download();

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

@if(isset($targetRow)&& isset($targetCol))表标签@for($row = 1; $row< = $targetRow 1; $row)tr标签@for($col = 1; $col< = $targetCol 1; $col)td标签@if($row == $targetRow&& $col == $targetCol)@include($的TargetView)@万一关闭td标签@endfor关闭tr标签@endfor关闭标签@万一

猜你在找的Laravel相关文章