Ext.grid.GridPanel 내보내기 Excel 생성

function Publicjs(){
 	
 }
 Publicjs.prototype = {
 	/**
	 *
	 * Ext grid Excel
	 *[ ]  IE
	 *param: gridId  Ext grid ID
	 */
 	extGridToExcel : function(gridId,sheetName){
 	  try{
	 		if(Ext.getCmp(gridId)){
				/********************************************* grid   Excel ***************************************/
				var oXL = new ActiveXObject("Excel.Application"); 
				var oWB = oXL.Workbooks.Add(); 
			    var oSheet = oWB.ActiveSheet; 
							
				var grid = Ext.getCmp(gridId);
				var store = grid.getStore();
				var recordCount = store.getCount();
				var view = grid.getView();
				var cm = grid.getColumnModel();
				var colCount = cm.getColumnCount();
				var temp_obj = [];
				for(var i = 0; i < colCount;i++){
					if(cm.isHidden(i)){
						
					}else{
						temp_obj.push(i);
					}
				}
				for(var i = 1; i <= temp_obj.length;i++){
					oSheet.Cells(1,i).value = cm.getColumnHeader(temp_obj[i - 1]);
				}
				
				for(var i = 1 ; i <= recordCount; i++){
					for(var j = 1; j<= temp_obj.length; j++){
						oSheet.Cells(i+1,j).value = view.getCell(i-1,temp_obj[j-1]).innerText; 
					}
				}
				if(sheetName){
					oSheet.Name = sheetName;
				}
				
				oXL.UserControl = true;
				oXL.Visible = true;
			}else{
				Ext.Msg.alert('Error',' grid !');
				return;
			}		
	 	}catch(e){
	 		if(Ext){
	 			Ext.Msg.show({
	 				title:' ',
	 				msg:' IE \' \'->Internet -> -> ->\' ActiveX \'-> [ ]&nbsp;&nbsp; Excel',
	 				buttons:Ext.Msg.OK,
	 				icon:Ext.Msg.INFO
	 			});
	 		}else{
	 			alert(' ExtJs ');
	 			return;
	 		}
 		}
 	}
 };

좋은 웹페이지 즐겨찾기