Assalamualaikum Wr. Wb. Hello everybody. For along times i dont publish article. And now i will share to you all about export data table to excel file without extension.
Okay, lets go.
the first, add menu with url to /site/export in main.php.
Second, open SiteController file and change this code to it.
Then click on menu export.
result of export excel.
It's easy, isn't? Now you can implement this method to your application project. So good luck. Thank you. Wassalamualaikum Wr. Wb.
Okay, lets go.
the first, add menu with url to /site/export in main.php.
Second, open SiteController file and change this code to it.
public function actionExport(){Well, now it's time to try it. Access your application!
$model = Mahasiswa::find()->All();
$filename = 'Data-'.Date('YmdGis').'-Mahasiswa.xls';
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=".$filename);
echo '<table border="1" width="100%">
<thead>
<tr>
<th>Mim</th>
<th>Nama</th>
<th>Jurusan</th>
<th>Angkatan</th>
<th>Alamat</th>
<th>Foto</th>
</tr>
</thead>';
foreach($model as $data){
echo '
<tr>
<td>'.$data['nim'].'</td>
<td>'.$data['nama'].'</td>
<td>'.$data['jurusan'].'</td>
<td>'.$data['angkatan'].'</td>
<td>'.$data['alamat'].'</td>
<td><img src="'.Yii::$app->request->baseUrl.'/uploads/'.$data['foto'].'" width="100px"></td>
</tr>
';
}
echo '</table>';
}
Then click on menu export.
result of export excel.
It's easy, isn't? Now you can implement this method to your application project. So good luck. Thank you. Wassalamualaikum Wr. Wb.