Product Prototypes:
Picture. png
Functional Requirements: Click the Export Attendance Form button, will be automatically downloaded into Excel format
Picture. png
Picture. png
JSP page code:
<div class="tools"><button type="button" class="btn green" id="excell" onclick="method5(‘dataTable‘)">导出考勤表</button></div>
JS Code
Print table Var idtmr; function GetExplorer () {var explorer = Window.navigator.userAgent; ie if (explorer.indexof ("MSIE") >= 0) {return ' IE '; }//firefox else if (Explorer.indexof ("Firefox") >= 0) {return ' Firefox '; }//chrome else if (Explorer.indexof ("Chrome") >= 0) {return ' chrome '; }//opera else if (Explorer.indexof ("opera") >= 0) {return ' opera '; }//safari else if (Explorer.indexof ("Safari") >= 0) {return ' Safari '; }} function Method5 (TableID) {if (getexplorer () = = ' ie ') {var curtbl = document.getElementById ( TableID); var OXL = new ActiveXObject ("Excel.Application"); var owb = OXL.Workbooks.Add (); var xlsheet = owb.worksheets (1); var sel = Document.body.createTextRange (); Sel.movetoelementtext (CURTBL); Sel.select (); Sel.execcommand ("Copy"); Xlsheet. Paste (); oXL.Visible = true; try {var fname = oXL.Application.GetSaveAsFilename ("Excel.xls", "Excel spreadsheets (*.xls), *.xls "); } catch (e) {print ("Nested catch caught" + e); } finally {Owb.saveas (fname); Owb.close (SaveChanges = false); Oxl.quit (); OXL = null; IDTMR = Window.setinterval ("Cleanup ();", 1); }} else {Tabletoexcel (tableid)}} function Cleanup () {Window.clearinterval (IDTMR ); CollectGarbage (); } var Tabletoexcel = (function () {var uri = ' data:application/vnd.ms-excel;base64, ', template = ' <HTML>&L T;head><meta charset= "UTF-8" >
Full copy of the pasted demo:
<! DOCTYPE html>
Front-end JS implementation print Excel table