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