Create JavaScript code _javascript tips for Word and Excel by copying table

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 "/>
<title> Untitled Document </title>
<script language= "JavaScript" >
function automatewordautopaging (prefixion,count)
{
var OWD = new ActiveXObject ("Word.Application");
var ODC = OWD.Documents.Add ();
Odc.showgrammaticalerrors = false; Screen grammar checking
Odc.showspellingerrors = false; Screen spell check
var oRange =odc.range (0,1);

for (i=0;i<count;i++)
{
var sel = Document.body.createTextRange ();
var tablename = Prefixion+i;
var Table = document.getElementById (tablename)
Sel.movetoelementtext (Table);
Sel.select ();
Sel.execcommand ("Copy");
OWD.Selection.Paste ();
OWD.Selection.InsertBreak (); Insert Page Break
}
Owd.activedocument.activewindow.view.type=3//Set Browse mode
Owd.visible = true;
};

function Automateexcel (prefixion)
{
var eltable = document.getElementById ("Automateexcel");
var orangeref = Document.body.createTextRange ();
Orangeref.movetoelementtext (eltable);
Orangeref.execcommand ("Copy");
try{
var appexcel = new ActiveXObject ("Excel.Application");
}catch (e)
{
Alert ("Cannot call Office objects, make sure your machine has Office installed and added the site name of this system to the list of trusted sites for IE!") ");
Return
}
Appexcel.visible = true;
APPEXCEL.WORKBOOKS.ADD (). Worksheets.item (1). Paste ();
Appexcel.workbooks (1). Worksheets.item (1). Columns ("A:a"). ColumnWidth = 100;
Appexcel.workbooks (1). Worksheets.item (1). Columns ("B:b"). ColumnWidth = 21;
Appexcel = null
};
</script>
<body>
<input type= button value= Export to Word auto page "onclick=" automatewordautopaging (' Table ', 5)/>
<input type= "button" value= "Export to Excel Control column width" onclick= "automateexcel (' Table ')"/>

<div id= "Automateexcel" >
<table class=tabp id= "Table0" cellspacing=0 cellpadding=2 "width=" 100% align=center
<TR>
&LT;TD width= "100%" align= "center" > title 0</td>
</TR>
<TR>
&LT;TD align= "center" > Content 0</td>
</TR>
</TABLE>
<BR>
<table class=tabp id= "Table1" cellspacing=0 cellpadding=2 "width=" 100% align=center
<TR>
&LT;TD width= "100%" align= "center" > title 1</td>
</TR>
<TR>
&LT;TD align= "center" > Content 1</td>
</TR>
</TABLE>
<BR/>
<table class=tabp id= "Table2" cellspacing=0 cellpadding=2 "width=" 100% align=center
<TR>
&LT;TD width= "100%" align= "center" > title 2</td>
</TR>
<TR>
&LT;TD align= "center" > Content 2</td>
</TR>
</TABLE>
<BR/>
<table class=tabp id= "Table3" cellspacing=0 cellpadding=2 "width=" 100% align=center
<TR>
&LT;TD width= "100%" align= "center" > title 3</td>
</TR>
<TR>
&LT;TD align= "center" > Content 3</td>
</TR>
</TABLE>
<BR/>
<table class=tabp id= "Table4" cellspacing=0 cellpadding=2 "width=" 100% align=center
<TR>
&LT;TD width= "100%" align= "center" > title 4</td>
</TR>
<TR>
&LT;TD align= "center" > Content 4</td>
</TR>
</TABLE>
<BR/>
</div>

</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.