zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    Daily Scrum02 12.05
    Daily Scrum02 12.04
    用户调研报告
    Daily Scrum02 12.03
    Daily Scrum02 12.02
    Daily Scrum02 12.01
    Daily Scrum02 11.30
    软件工程项目组Z.XML会议记录 2013/11/27
    Daily Scrum02 11.29
    201509-3 模板生成系统
  • 原文地址:https://www.cnblogs.com/wujixing/p/5920289.html
Copyright © 2011-2022 走看看