0
votes

I'm using Maatwebsite/Laravel-Excel. And I need to export a view file to xls format using the codes below.

Controller File:

public function excel(){
   return Excel::download(new Export($id), 'test.xls');
}

Export File

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

public function view(): View {
    $obj = Object::find($this->id);

    return view('project.view', [
        'var' => $obj,
    ]);
}

The exported file is looking a bit good.

But my concern is, how to make the cells , auto width, depending on the content, and the styles, border are gone.

1
What exactly is your question? How to make the cells auto width, how to style cells or how to add borders to cells?Loek
@Loek all of those you mentioned.Lucentyr

1 Answers

0
votes

Try This Way.

use Excel;
$data=array();
Excel::create('Sheet Name', function($excel) use($data) {

     $excel->sheet('Sheet', function($sheet) use($data){
      $sheet->setOrientation('landscape');
         $sheet->loadView('view',compact('data'));

    });

  })->export('xls');