-4

Hello Sir I want to ask how to export my few tables data in excel sheet format in list manner

jherran
  • 3,337
  • 8
  • 37
  • 54

2 Answers2

0

You can use this https://github.com/kartik-v/yii2-export or something like this:

public function actionDownloadExcel() {
    $data = <here some query>;
    $data = unserialize( $data);
    header( 'Content-Type: text/csv; charset=windows-1251' );
    header( 'Content-Disposition: attachment; filename=data.csv' );
    $output = fopen( 'php://output', 'w' );
    fwrite( $output, "\xEF\xBB\xBF" );
    fputcsv( $output, [ 'field1', 'field2', 'field3' ], ';' );
    foreach ( $data as $key => $value ) {
        fputcsv( $output, $value, ';' );
    }
}

in you Controller. More documentation at http://php.net/manual/ru/function.fputcsv.php

  • Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others and provide the link for reference. – Tim Diekmann May 22 '18 at 19:34
0

I'm not exactly sure what you mean by "list manner" but you could create a link that uses CListView and use the template attributes to only use your view 'template'=>'{items}', and turn off paging. Then set the header of your file with php for the appropriate file type, etc. If you need something more sophisticated than CSV, see here.

Community
  • 1
  • 1
ldg
  • 9,112
  • 2
  • 29
  • 44