table导出到excel的两种方法


需要下载jquery.table2excel.js插件 引用后

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

         <script src= "<%=request.getContextPath()%>/js/jquery.table2excel.js" ></script>
 
jquery
function exportexcel(){
                 $( "#tableServer" ).table2excel({
                     exclude:  ".noExl" ,
                     name:  "Excel Document Name" ,
                     filename:  "myFileName" ,
                     exclude_img:  true ,
                     exclude_links:  true ,
                     exclude_inputs:  true
                 });
             }
tableServer 导出table的id  .noExl是不需要导出的标签的class 哪行不需要导出class 加上noExl 
 
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 ;
             }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM