Use Javascript to export a WORD in a specified area of an Html page

Source: Internet
Author: User

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

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.