table導出到excel的兩種方法


1. 用table2excel 的js文件,這種方法沒有IE兼容性

需要在文件中導入

<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
  		<script src="<%=request.getContextPath()%>/js/jquery.table2excel.js"></script>

 然后再文件中寫方法

function exportexcel(){
		        $("#tableServer").table2excel({
		            exclude: ".noExl",
		            name: "Excel Document Name",
		            filename: "myFileName",
		            exclude_img: true,
		            exclude_links: true,
		            exclude_inputs: true
		        });
		 	}

 

2. js代碼

function ExportToExcel() {
	  	        var elTable = document.getElementById("tableServer"); //你的tableID
	  	        var oRangeRef = document.body.createTextRange();
	  	        oRangeRef.moveToElementText(elTable);
	  	        oRangeRef.execCommand("Copy");
	  	        try {
	  	            var appExcel = new ActiveXObject("Excel.Application");
	  	        } catch (e) {
	  	            alert("If you change your mind, refresh your page  and select 'yes' to download excel.");
	  	            return;
	  	        }
	  	        appExcel.Visible = true;
	  	        appExcel.Workbooks.Add().Worksheets.Item(1).Paste();
	  	        appExcel = null;
	  	    }

 jsp代碼

<a href="javascript:void(0);" onclick="javascript:ExportToExcel()">
	<img src="${pageContext.request.contextPath}/style/images/excel6.jpg"   width=20px height=20px style="padding-top:15px"/>
</a>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM