yii2-postman4excel postman export excel

use ptrnov\postman4excel\Postman4ExcelBehavior;
public function behaviors(){
        'export4excel' => [
	       'class' => Postman4ExcelBehavior::className(),
                'downloadPath'=>'your path'
                'widgetType'=>'download'
                'widgetType'=>'cronjob' 
		//'prefixStr' => yii::$app->user->identity->username,
	        //'suffixStr' => date('Ymd-His'),
	       'columnAutoSize'=>'true', //false/true; default True
				
			],
	}
	
// localhost/yourController/test-export
public function actionTestExport()
{
        //get data from database
        $sqlDataProvider= new ArrayDataProvider([
	     'allModels'=>\Yii::$app->db->createCommand("	
			SELECT id, username FROM user
	     ")->queryAll(), 
	]);	
	$arySqlDataProvider=$sqlDataProvider->allModels;	
		
	/*Array Model Data*/
	$excel_dataAll = Postman4ExcelBehavior::excelDataFormat($arySqlDataProvider);
	$excel_ceilsAll = $excel_dataAll['excel_ceils'];
	$excel_title1 = $excel_dataAll['excel_title'];
	$excel_title2 = ['ID','USERNAME'];
		
	//Tite Header From Table Name
	//$excel_title = $excel_dataAll['excel_title'];
		
	//Tite Header From Modify byself
	//$excel_title = ['ID','USERNAME']
				
	//Note 'sheet_title'
	//old version : 'sheet_title' => $excel_title,
	//new Version : 'sheet_title' => [$excel_title1,$excel_title2,$excel_title3, dst],
		
		
	$excel_content = [
		[
		        'sheet_name' => 'TEST EXPORT 1',
                        'sheet_title' => $excel_title1, 	//old version				
		        'ceils' => $excel_ceilsAll,
			//'freezePane' => 'E2',
                        //All Header Color font and Backgroud
                        'headerColor' => Postman4ExcelBehavior::getCssClass("header"),	
                        'headerColumnCssClass' => [//old version
			    [
				'id' => Postman4ExcelBehavior::getCssClass('yellow'),
			        'username' => Postman4ExcelBehavior::getCssClass('green'),
			    ],
			    [
			        'ID' => Postman4ExcelBehavior::getCssClass('red'),  
				'USERNAME' => Postman4ExcelBehavior::getCssClass('green'), 						 
			    ]             
                             
                           ],
                           'oddCssClass' => Postman4ExcelBehavior::getCssClass("odd"),
                           'evenCssClass' => Postman4ExcelBehavior::getCssClass("even"),
		],
		[
			'sheet_name' => 'TEST EXPORT 2',
			//'sheet_title' => [$excel_title1], //new version | one Header
                        'sheet_title' => [ //new version | two or more Header
				$excel_title1,
				$excel_title2
			], 	//new version				
			'ceils' => $excel_ceilsAll,
			//'freezePane' => 'E2',
                        //old Version | All Header Color font and Backgroud
                        'headerColor' => Postman4ExcelBehavior::getCssClass("header"),	            
				/* --------------------------------------------------------
				 * customize Header properties
				 * Color Ref: http://dmcritchie.mvps.org/excel/colors.htm
				 * columnAutoSize=false, width is Active
				 * 'merge'=>'col,row'
				 * Content properties, validate on use last column title
				 * --------------------------------------------------------
				 */
			'headerStyle' => [//new version
			      [	//the first Header						
				'id' => [
                                            'align'=>'CENTER',
                                            'color-font'=>'0000FF',
                                            'color-background'=>'FFCCCC',
                                            'merge'=>'0,2','width'=>'2,0'
                                 ],
				'username' => [
                                            'align'=>'left',
                                            'color-font'=>'FF0000',
                                            'color-background'=>'CCFF99','merge'=>'2,1'
                                ], 
			],
			[//The second Header
				'ID' =>  [
                                            'align'=>'right',
                                            'color-font'=>'0000FF',
                                            'color-background'=>'CCFFCC'
                                 ],
				'USERNAME' =>  [
                                             'align'=>'right',
                                             'color-font'=>'000000', 
                                             'color-background'=>'FFFF99'
                                 ],				 
			]                              
                ],  
		'contentStyle' => [ //new version
		        [//the first Content
			   //'id' => ['align'=>'left'],
			   //'username' => ['align'=>'right'],
			],
			[//The second Content
			   'ID' =>  ['align'=>'center','color-font'=>'0000FF'],
			   'USERNAME' =>  ['align'=>'center','color-font'=>'0000FF'],				 
			],                              
                ],  
               'oddCssClass' => Postman4ExcelBehavior::getCssClass("odd"),
               'evenCssClass' => Postman4ExcelBehavior::getCssClass("even"),
	    ],
			
    ];
		
    $excelFile = "TestExport";
   $this->export4excel($excel_content, $excelFile); 	
}
0 0
2 followers
128 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: Others
Developed by: ptr.nov
Created on: Aug 30, 2016
Last updated: 8 years ago

Downloads

show all