프런트엔드에서 excel 파일 내보내기

3878 단어
페이지 정의:

js 코드:
 exportExcel :function(){
	        	var data = temperature.$illuminationDatagrid.datagrid("getData");
	        	if(data.total == 0){
	        		 $.messager.alert(" "," , !","info");
	        	}else{
	        		 $.messager.confirm(" "," ?",function(r){
	        			 if(r){
	        				 var timeStatistics = temperature.$timeStatistics.combobox("getValue"),
	        				 columnFields = temperature.$illuminationDatagrid.datagrid("getColumnFields"),
	        				 hide0 = ["avgSSH"],
	        				 hide1 = ["sSH"],
	        				 columnField = [];
	        				 // 
	        				 if(timeStatistics == 0){
	        					 columnField = hide0;
	        				 }else{
	        					 columnField = hide1;
	        				 }
	        				 for(var i = 0 ; i < columnField.length ; i++){
	        					 if(columnFields.indexOf(columnField[i]) > -1){
	        						 columnFields.splice(columnFields.indexOf(columnField[i]),1);
	        					 }
	        				 }
	        				// title
	                         var colName=[];
	                         for( i = 0 ; i < columnFields.length ; i++){
	                             var col = temperature.$illuminationDatagrid.datagrid( "getColumnOption" , columnFields[i] );
	                             colName.push(col.title);// TITLEPUSH 
	                         }
	                         
	                         // table
	                         var talbleHtml = [],$excelTable = $('table[role="excel_table"]'),sortFields = [];
	                         $excelTable.html("");

	                         talbleHtml.push('');
	                         for(var i = 0 ;i < colName.length ; i++){
	                             talbleHtml.push('' + colName[i] + '');
	                         }
	                         talbleHtml.push('');
	                        console.log(data);
	                         // 
	                         for(var i = 0 ; i < data.rows.length ; i++){
	                        	 
	                        	 talbleHtml.push('');
	                             var rowObject = data.rows[i];// 
	                             for(var j = 0 ; j < columnFields.length ; j++){
	                            	 for(var field in rowObject){
	                            		 if(field == columnFields[j]){
	                            			 if(field == "datetime"){
	                                             talbleHtml.push('' + new Date(rowObject[field]).format("yyyy-MM-dd hh:mm:ss") + '');
	                            			 }else{
	                                             talbleHtml.push('' + rowObject[field] + '');
	                            			 }
	                            		 }
	                            	 }
	                             }
	                             talbleHtml.push('');
	                         }
	                         $excelTable.append(talbleHtml.join(""));
	                       // null 
	                         $excelTable.find(".excel_td_null").each(function(i,item){
	                             var context = $(this).html();
	                             if(context == "null"){
	                                 $(this).html("");
	                             }
	                         });
	                         tableToExcel("excel_table"," ");
	        			 }
	        		 })
	        	}
	        }

좋은 웹페이지 즐겨찾기