table 转 excel 无插件


function base64(content) {
		return window.btoa(unescape(encodeURIComponent(content)));
}

function tableToExcel(tableID, fileName) {
	var excelContent = $("#" + tableID).html();
	var excelFile = "";
	excelFile += "";
	excelFile += "";
	excelFile += excelContent;
	excelFile += "
"; excelFile += ""; var link = "data:application/vnd.ms-excel;base64," + base64(excelFile); var a = document.createElement("a"); a.download = fileName + ".xls"; a.href = link; a.click(); }

html代码


	<%
		for (Map data : dataList) {
	%>
	
	<%
		}
	%>
	
公证员 助手 年度 类别 证号 当事人 受理时间 审批时间
<%=data.get("notryName")%> <%=data.get("assistantName")%> <%=data.get("year")%> <%=data.get("typeName")%> <%=data.get("serialNumber")%> <%=data.get("partyName")%> <%=data.get("acceptDate")%> <%=data.get("approveDate")%>
纯js实现方式
通过table的Class导出excel
var tableClass = document.getElementsByClassName('ant-table-fixed');
tableClass[0].id = 'tableExcel';
var tableItem = document.getElementById('tableExcel');
var excelContent = tableItem.innerHTML;
var excelFile = "";
excelFile += "";
excelFile += "";
excelFile += excelContent;
excelFile += "
"; excelFile += ""; var link = "data:application/vnd.ms-excel;base64," + window.btoa(unescape(encodeURIComponent(excelFile))); var a = document.createElement("a"); a.download = "邮费统计.xls"; a.href = link; a.click();

 

你可能感兴趣的:(javaScript,html,excel)