用javascript操作word文档
类别: JavaScript教程
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>
- 上一篇: 有分页功能的WEB打印
- 下一篇: 用Javascript使网页图片产生旋转效果
-= 资 源 教 程 =-
文 章 搜 索