[JavaScript] under IE, copy table and support paste into Excel

Source: Internet
Author: User
Tags jqgrid

Key code:

Jsutils = {selectedrange:function(EL) {// <summary>            /// selected content            ///Eg:selectedrange (document.getElementById (' 123 '));            // </summary>            /// <param name= "El" > Need to select Objects </param>            varBODY = document.body, range, sel;if(Document.createrange && window.getselection) {The //range object represents a contiguous range of documents, such as a user dragging a selected area with the mouse in a browser window.                 //selection is the current active selection (that is, the highlighted text). Range = Document.createrange ();                sel = Window.getselection (); Sel.removeallranges ();Try{range.selectnodecontents (EL);                Sel.addrange (range); }Catch(e) {Range.selectnode (EL);                Sel.addrange (range); }            }Else if(body.createtextrange) {range = Body.createtextrange ();                Range.movetoelementtext (EL);            Range.Select (); }        }    };
 Ieuitls = {copyelectoclipboard: function  (elecid) {            ///<summary>             ///only supports Internet Explorer's copy of HTML elements to the Clipboard             ///</summary>             ///<param name= "elecid" > Need to copy id</param>             var  obj = document.getElementById (elecid); if  (obj)                {jsutils.selectedrange (obj);            Document.execcommand ( ' copy ' , true ); }        }    };

Implementation code:

 function Copy () {///<summary>  ///copy the latitude and longitude table data to the Clipboard  ///</summary>  //var RowIds = $ (" #list4 "). Jqgrid (' Getdataids ');             //if (rowIds) { //var copydate = ';         //for (var i = 0, j = rowids.length; I < J; i++) { //            var currowdata = $ ("#list4"). Jqgrid (' GetRowData ', rowids[i]);             //copydate + = currowdata[' lat '] + ' + currowdata[' lng ' + ' \ n ';             //}             //Ieuitls.copytexttoclipboard (copydate);             //}         Ieuitls.copyelectoclipboard ( ' list4 ' ); }

Copy and paste to Excel like:

Hope to be helpful!

[JavaScript] under IE, copy table and support paste into Excel

Related Article

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.