当前位置导航:炫浪网>>网络学院>>网页制作>>JavaScript教程

用Javascript操作word文档

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>

相关内容
赞助商链接