JS Export table data to Excel is the way to export Excel documents _javascript tips

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
How to export a <title>web page to an Excel document </title>
<body>
<table id= "Tableexcel" width= "100%" border= "1" cellspacing= "0" cellpadding= "0" >
<tr>
&LT;TD colspan= "5" align= "Center" >
How a Web page is exported as an Excel document
</td>
</tr>
<tr>
<td>
Column Heading 1
</td>
<td>
Column Heading 2
</td>
<td>
Column Heading 3
</td>
<td>
Column Heading 4
</td>
<td>
Column Heading 5
</td>
</tr>
<tr>
<td>
Aaa
</td>
<td>

</td>
<td>
Ccc
</td>
<td>
Ddd
</td>
<td>
Eee
</td>
</tr>
<tr>
<td>
Aaa
</td>
<td>

</td>
<td>
Ccc
</td>
<td>
Ddd
</td>
<td>
EEE
</td>
</tr>
<tr>
<td>
FFF
</td>
<td>
GGG
</td>
<td>
HHH
</td>
<td>
Iii
</td>
<td>
Jjj
</td>
</tr>
</table>
<input type= "button" onclick= javascript:method1 (' Tableexcel '); "value=" first method import to Excel >

<script language= "JavaScript" >

function Method1 (tableid) {//Full table Copy to Excel

var curtbl = document.getElementById (TableID);

var oXL = new ActiveXObject ("Excel.Application"); Create an Ax object Excel

var owb = OXL.Workbooks.Add (); Get Workbook Object

var osheet = Owb.activesheet; Activate current sheet

var sel = Document.body.createTextRange ();

Sel.movetoelementtext (CURTBL); Move the contents of the table to TextRange

Sel.select (); Full selection of TextRange contents

Sel.execcommand ("Copy"); Copy content in TextRange

Osheet.paste (); Paste into active Excel

oXL.Visible = true; Set Excel Visible Properties

}


</script>

</body>

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.