mumunotes

  • Home
  • Contact Us

Tuesday, 11 August 2015

Export Data to Excel Without Extension on Yii2

 mumunotesss     12:59     Yii, Yii2     No comments   

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.
public function actionExport(){
    $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>';

}
Well, now it's time to try it. Access your application!

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.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

About Me

mumunotesss
View my complete profile

Popular Posts

  • Change password with validation and repeat password on Yii2
    Hello everybody. I could not post an article because I didn't have new knowledge to share. Ok, this day I will share about "...
  • Import Data from CSV File to Database Without Extension in Yii2
    Hello everybody, Assalamualaikum Wr. Wb. Nearly 1 month I don't publish article. Now, I publish an article about " Import Data fro...
  • Membuat login Yii2 dengan Database
    Selamat pagi guys. Sorry beberapa hari kamaren sibuk. Jadi belum sempet update blog lagi. Mumpung kali ini sempet, hari ini mau berbagi te...
  • Membuat fungsi CRUD dengan Gii Yii2
    Selamat pagi guys. Setelah kemaren kita membuat login dari database, hari ini kita akan membuat CRUD (create, read, update, delete) dengan ...

Blog Archive

  • ▼  2015 (16)
    • ►  November (1)
    • ►  September (1)
    • ▼  August (1)
      • Export Data to Excel Without Extension on Yii2
    • ►  June (8)
    • ►  May (5)

Translate

Copyright © mumunotes
Distributed By My Blogger Themes | Blogger Theme By NewBloggerThemes