Thursday, May 17, 2018

How to call different methods of other classes to make a sheet and then merge sheet return from these methods to a excel file in Laravel? - development

How to call different methods of other classes to make a sheet and then merge sheet return from these methods to a excel file in Laravel?

I am using maatwebsite/Laravel-Excel to make excel sheet. What I need is I want to make 5 sheets in a single file I am able to make when using a common function to generate all sheets. But I want to make a sheet from the different function of some different class and then return this sheet to the calling function where we can merge different sheets to a single file.

The scenario is that:
1. We have a function where we will make a single file with 5 sheets.

    Excel::create($fileName, function ($excel) use ($productArray){
    //some code
    $excel->sheet($sheet_name, function ($sheet) use ($productArray){

    if($sheet_name=='test'){
    $x  = new abcController;
    $y = $x->exportComment();//it should return a sheet so that it can 
    be 
    merged
    }

    });

    });

  1. For first sheet we call a method like

    $x  = new abcController;
    $y = $x->exportComment();
    
    
  2. This exportComment() function will do like

    Excel::create('comment', function ($excel) use ($productArray){
    //some code
    $excel->sheet('comment', function ($sheet) use ($productArray){
    
    //code for generating sheet data(like row and cols etc.)
    }
    
    });
    
    });
    
    

now this exportComment() function will create a sheet (its working fine).
But how to return that sheet to the calling function?

I am not able to get proper answer. If anyone I can explain more clearly?

Please help whether I am going right or wrong.



from Laravel Questions and Answers https://laravelquestions.com/php/how-to-call-different-methods-of-other-classes-to-make-a-sheet-and-then-merge-sheet-return-from-these-methods-to-a-excel-file-in-laravel/
via Lzo Media

No comments:

Post a Comment