用javascript操作word文档

发表于:2007-06-21来源:作者:点击数: 标签:
1、 向word中写入内容 首先在word中设置书签,如书签名为bookmark, java script中可以这样写 var word; word = new ActiveXObject("Word.Application"); var range = word.Range; word.Visible = true; var path = "filepath"; word.Documents.Open(path);

   

1、 向word中写入内容


首先在word中设置书签,如书签名为bookmark,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("哈哈哈哈哈哈");


2、把word文件转成html文件


<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 the "save" button to save the file "C:\test.doc" to "C:\test.htm":
<input type=button onclick="saveword()" value=save>

</BODY>
</HTML>

原文转自:http://www.ltesting.net