Copy codeThe Code is 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>
<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>
<TD colSpan = 4 style = "text-align: center;"> cell merge Row B </TD>
</TR>
</TABLE>
<Br/>
<Input type = "button" onclick = "javascript: AllAreaWord ();" value = "export the content of the specified area on the page to Word">
<Input type = "button" onclick = "javascript: AllAreaExcel ();" value = "export the content of a specified area on the page to Excel">
<Input type = "button" onclick = "javascript: CellAreaExcel ();" value = "export the content of a form cell to Excel">
<Script language = "javascript">
// Import the content of the specified page area to 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.exe cCommand ("Copy ");
OSheet. Paste ();
OXL. Visible = true;
}
// Specify the "cell" content in the page area to import to 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;
}
// Import the content of the specified page area to the Word
Function AllAreaWord ()
{
Var oWD = new ActiveXObject ("Word. Application ");
Var oDC = oWD. Documents. Add );
Var oRange = oDC. Range (0, 1 );
Var sel = document. body. createTextRange ();
Sel. moveToElementText (PrintA );
Sel. select ();
Sel.exe cCommand ("Copy ");
ORange. Paste ();
OWD. Application. Visible = true;
// Window. close ();
}
</SCRIPT>