<HTML> <HEAD> <Title> How to export an EXCEL document from a WEB page </Title> </HEAD> <Body> <BR> <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> <BR> <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 to Word"> <Input type = "button" onclick = "javascript: AllAreaExcel ();" Value = "export the content of a specified area 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> </Body> </Html> |