Programatically Of Export To Excel & Select All Gridview

I have 2 question about yii2 implementation:

  1. Could anybody explain for me and give me code example about export to excel (with phpexcel) base on Gridview… for example in yii 1… I use EexcelView a simple extension to export. (I know about extension but I want explanation :) )

  2. Could anybody explain for me about select all in gridview and then do action for example delete selected… how code in view (gridview and javascript) and then how code in controller to response array of request…


wondering if CSV, does not meet your requirement? if it does, i can help, you with a code how to create a csv file. you can just change the file extension if to xls if you prefer. not sure what would be the implications though.

ok no problem in csv… please explain for me?

okay, in your model:

	public function outputCSV($dataProvider,$fileName = 'myCSVfile.csv') {

			header("Content-type: text/csv");

			header("Content-Disposition: attachment; filename=".$fileName);

			header("Pragma: no-cache");

			header("Expires: 0");

			$header = array('Column 1', 'Column 2', 'column 3', 'column 4', 'column 5');

			$list =array();

			array_push($list, $header);

			foreach ($dataProvider as $data) {

					$row = array(







					 array_push($list, $row);


		    $output = fopen("php://output", "w");

		    foreach ($list as $row) {

		        fputcsv($output, $row); // here you can change delimiter/enclosure





you just have to modify the header and the data you want to output.

in you controller admin

  	public function actionAdmin($hotel_id,$export=NULL)


		$model=new Reservations('search');

		$model->unsetAttributes();  // clear any default values



		if($export== 1)








now you can download a csv file, by adding export=1 to your URL like so: