1. Write content to word
First, set bookmarks in word, such as bookmark, which can be written in JavaScript.
VaR word;
Word = New Activexobject ( " Word. Application " );
VaR range = Word. range;
Word. Visible = True ;
VaR path = " Filepath " ;
Word. Documents. Open (PATH );
Range = Word. activedocument. bookmarks ( " Bookmark " ). Range;
Range. insertbefore ( " Haha " ); // Insert content after bookmarks
//----- The followingCodeSection attaching protection and canceling protection documentation functions ----
// Protected document, editable at bookmarks
Range. Select (); // Selected bookmarks
VaR psw = ' 123 '
Word. activedocument. bookmarks ( " Bookmark " ). Range. Editors. Add ( - 1 ); // Constant: wdeditoreveryone =-1
Word. activedocument. Protect ( 3 , False , Psw, False , False ); // Constant: wdallowonlyreading = 3
// Cancel protection document
Word. activedocument. unprotect (psw );
//----------------------- End --------------
2. convert a Word file into an HTML file
< Script Language = Javascript >
Function saveword (){
VaR owordapp = New Activexobject ( " Word. Application " );
VaR odocument = Owordapp. Documents. Open ( " C: \ doc2html \ x.doc " );
Odocument. saveas ( " C: \ test.htm " , 8 )
Owordapp. Quit ();
}
</ Script >
</ Head >
< Body >
Click " Save " Button to save the file " C: \ test.doc " To " C: \ test.htm " :
< Input type = Button onclick = " Saveword () " Value = Save >
body >
HTML >