• 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>
    
  • 相关阅读:
    网络流(平面图转对偶图)
    666
    期望总结
    docker-1-简介
    22、整合mybatis
    21、整合Druid数据源
    20、Springboot 与数据访问(JDBC/自动配置)
    19、配置嵌入式servlet容器(下)
    18、配置嵌入式servlet容器(2)
    17、配置嵌入式servlet容器(1)
  • 原文地址:https://www.cnblogs.com/wujixing/p/5920289.html
Copyright © 2020-2023  润新知