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>