1 2 3 <title> test exporting HTML content to WORD </title>
4 <script type = "text/javascript" language = "javascript">
5 // import the content of the specified page area to the Word
6 function exportToWord (controlId ){
7 var control = document. getElementById (controlId );
8 try {
9 var oWD = new ActiveXObject ("Word. Application ");
10 var oDC = oWD. Documents. Add ("", 0, 1 );
11 var oRange = oDC. Range (0, 1 );
12 var sel = document. body. createTextRange ();
13 try {
14 sel. moveToElementText (control );
15} catch (notE ){
16 alert ("failed to export data. No data can be exported. ");
17 window. close ();
18 return;
19}
20 sel. select ();
21 sel.exe cCommand ("Copy ");
22 oRange. Paste ();
23 oWD. Application. Visible = true;
24 // window. close ();
25}
26 catch (e ){
27 alert ("failed to export data. You need to install Microsoft Office Word (unlimited version) on the customer's machine, add the current site to the trusted site, and allow you to run ActiveX controls in IE. ");
28 try {oWD. Quit ();} catch (ex ){}
29 // window. close ();
30}
31}
32 </script>
33 34 <body>
35 <div id = "TestDiv">
36 <div align = "center"> three seasons of Love apartment </div>
37
38 <table width = "100%">
39 <tr>
40 <td style = "background-color: # F50AE5; font-weight: bold; text-align: center">
41 rankings
42 </td>
43 <td style = "background-color: # F50AE5; font-weight: bold; text-align: center">
44 name
45 </td>
46 <td style = "background-color: # F50AE5; font-weight: bold; text-align: center">
47 total score
48 </td>
49 </tr>
50 <tr>
51 <td style = "text-align: center">
52 2012001
53 </td>
54 <td style = "text-align: center">
55 Zeng xiaoxian
56 </td>
57 <td style = "text-align: center">
58 86
59 </td>
60 </tr>
61 <tr>
62 <td style = "text-align: center">
63 2012002
64 </td>
65 <td style = "text-align: center">
66 Hu Yifei
67 </td>
68 <td style = "text-align: center">
69 85
70 </td>
71 </tr>
72 </table>
73 </div>
74 <div>
75 <div style = "text-align: center">
76 <input type = "button" value = "export to WORD" onclick = "return exportToWord ('testdiv ')"/>
77 </div>
78 </body>
79 80