引入jS
<script type="text/javascript" src="/Public/js/jquery.2.2.4.min.js"></script> <script type="text/javascript" src="/Public/js/jquery.table2excel.js"></script>
下载链接:
https://files.cnblogs.com/files/blogs/727088/jquery.table2excel.js?t=1692939270&download=true
https://files.cnblogs.com/files/blogs/727088/jquery.2.2.4.min.js?t=1692939270&download=true
body部分
<p ><button class="exportBtnClass">点击导出表格</button> </p> <table id="table1" > {$table_content} </table>
JS部分: 这是一个标记重复值的demo
$(document).ready(function() { let tds=$('td'); let jj={}; tds.each(function(i,e){ if (i==6 || (i-6)%9==0){ // console.log(i,'==>',$(e),'==>',$(e).text(),'==>', $(e).parent()); $(e).parent().addClass($(e).text()); /*计数*/ if( jj[$(e).text()]){ jj[$(e).text()]++; }else{ jj[$(e).text()]=1; } } } ) // console.log(jj); for (let i in jj){ // console.log('属性名为:',i) // console.log('值为:',jj[i]) if(jj[i]>1){ let sel_tr=$("."+i); // sel_tr.css("background", "yellow"); // console.log(sel_tr.children("td")); sel_tr.children("td").css("background", "yellow");/*table2excel.JS 导出样式需要在td上加样式*/ } } //导出表格 $(".exportBtnClass").click(function(e){ var table = $("#table1") ; if(table && table.length){ $(table).table2excel({ filename: "filename.xls", sheetName: 'Sheet1', fileext: ".xls", //File extension type preserveColors: true //是否带样式 }); } }); }); </script>
标签:console,log,表格,text,excel,jq,jj,table,sel From: https://www.cnblogs.com/agfox123/p/17656653.html