JavaScript clients export the specified area to Word, Excel code _javascript tips

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

<table id = "PrintA" width= "100%" border= "1" cellspacing= "0" cellpadding= "0" bgcolor = "#61FF13" >
<tr style= "Text-align:center;" >
<TD> Cell a</td>
<TD> Cell a</td>
<TD> Cell a</td>
<TD> Cell a</td>
</TR>
<TR>
&LT;TD colspan=4 style= "Text-align:center;" ><font color= "BLUE" face= "Verdana" > Cell merge Row a</font></td>
</TR>
</TABLE>
<table id = "PRINTB" width= "100%" border= "1" cellspacing= "0" cellpadding= "0" >
<tr style= "Text-align:center;" >
<TD> Cell b</td>
<TD> Cell b</td>
<TD> Cell b</td>
<TD> Cell b</td>
</TR>
<TR>
&LT;TD colspan=4 style= "Text-align:center;" > Cell Merge Row b</td>
</TR>
</TABLE>
<br/>
<input type= "button" onclick= Javascript:allareaword (); "value=" Export page Specify area content to Word >
<input type= "button" onclick= javascript:allareaexcel (); "value=" Export page specify area content to Excel >
<input type= "button" onclick= javascript:cellareaexcel (); "value=" Export table meta content to Excel >

<script language= "JavaScript" >
Specify page area content import Excel
function Allareaexcel ()
{
var oXL = new ActiveXObject ("Excel.Application");
var owb = OXL.Workbooks.Add ();
var osheet = Owb.activesheet;
var sel=document.body.createtextrange ();
Sel.movetoelementtext (PrintA);
Sel.select ();
Sel.execcommand ("Copy");
Osheet.paste ();
oXL.Visible = true;
}
Specify the page area cell content import Excel
function Cellareaexcel ()
{
var oXL = new ActiveXObject ("Excel.Application");
var owb = OXL.Workbooks.Add ();
var osheet = Owb.activesheet;
var lenr = PrintA.rows.length;
for (i=0;i<lenr;i++)
{
var Lenc = printa.rows (i). Cells.length;
for (j=0;j<lenc;j++)
{
Osheet.cells (i+1,j+1). Value = Printa.rows (i). Cells (j). innertext;
}
}
oXL.Visible = true;
}
Specify page area content import Word
function Allareaword ()
{
var OWD = new ActiveXObject ("Word.Application");
var ODC = OWD.Documents.Add ("", 0, 1);
var oRange =odc.range (0,1);
var sel = Document.body.createTextRange ();
Sel.movetoelementtext (PrintA);
Sel.select ();
Sel.execcommand ("Copy");
Orange.paste ();
OWD.Application.Visible = true;
Window.close ();
}
</SCRIPT>

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.