Generate javascript code for word and excel by copying Table

Source: Internet
Author: User

Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<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; // block syntax check
ODC. ShowSpellingErrors = false; // mask the spelling 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.exe cCommand ("Copy ");
OWD. Selection. Paste ();
OWD. Selection. InsertBreak (); // insert a paging character
}
// OWD. ActiveDocument. ActiveWindow. View. Type = 3 // set the browsing mode
OWD. Visible = true;
};

Function AutomateExcel (prefixion)
{
Var elTable = document. getElementById ("AutomateExcel ");
Var oRangeRef = document. body. createTextRange ();
ORangeRef. moveToElementText (elTable );
ORangeRef.exe cCommand ("Copy ");
Try {
Var appExcel = new ActiveXObject ("Excel. Application ");
} Catch (e)
{
Alert ("The Office object cannot be called. Please make sure that your machine has installed Office and the site name of the system has been added to the trusted site list of 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>
</Head>
<Body>
<Input type = "button" value = "export to Word automatic paging" 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 border = 1>
<TR>
<TD width = "100%" align = "center"> title 0 </TD>
</TR>
<TR>
<TD align = "center"> content 0 </TD>
</TR>
</TABLE>
<BR>
<TABLE class = tabp id = "Table1" cellSpacing = 0 cellPadding = 2 width = "100%" align = center border = 1>
<TR>
<TD width = "100%" align = "center"> Title 1 </TD>
</TR>
<TR>
<TD align = "center"> content 1 </TD>
</TR>
</TABLE>
<BR/>
<TABLE class = tabp id = "Table2" cellSpacing = 0 cellPadding = 2 width = "100%" align = center border = 1>
<TR>
<TD width = "100%" align = "center"> Title 2 </TD>
</TR>
<TR>
<TD align = "center"> content 2 </TD>
</TR>
</TABLE>
<BR/>
<TABLE class = tabp id = "Table3" cellSpacing = 0 cellPadding = 2 width = "100%" align = center border = 1>
<TR>
<TD width = "100%" align = "center"> Title 3 </TD>
</TR>
<TR>
<TD align = "center"> content 3 </TD>
</TR>
</TABLE>
<BR/>
<TABLE class = tabp id = "Table4" cellSpacing = 0 cellPadding = 2 width = "100%" align = center border = 1>
<TR>
<TD width = "100%" align = "center"> Title 4 </TD>
</TR>
<TR>
<TD align = "center"> content 4 </TD>
</TR>
</TABLE>
<BR/>
</Div>

</Body>
</Html>

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.