Wednesday, October 5, 2022

[FIXED] How to copy a sheet to another in php laravel excel?

Issue

my question is as the title said ! how can i copy an excel sheet content to another using laravel excel of maatwebsite!

Excel::load(Input::file('file'), function($file)
    {     
        $sheet1 = $file->setActiveSheetIndex(0);
        Excel::create('Filename', function($excel) use($sheet1) {
            // Create first sheet
            $excel->sheet('First sheet', function($sheet) use ($sheet1){
                $sheet = $sheet1;
            });
        })->export('xls');
    });

Solution

Excel::load(Input::file('file'), function($file)
    {     
        $sheet1 = $file->setActiveSheetIndex(0);
        Excel::create('Filename', function($excel) use($sheet1) {
            // add $sheet1 for new file
            $excel->addExternalSheet($sheet1)
        })->export('xls');
    });


Answered By - Rex
Answer Checked By - Mildred Charles (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.