Front-end JS implementation print Excel table

Source: Internet
Author: User
Tags base64 button type setinterval

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 = ' &LT;HTML&GT;&L T;head><meta charset= "UTF-8" >

Full copy of the pasted demo:

<! DOCTYPE html>

Front-end JS implementation print Excel table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.