87,904
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>HighLight</title>
</head>
<script language="javascript">
function highlight(){
var wdapp = null;
try {
wdapp = new ActiveXObject ("Word.Application");
wdapp.visible = true;
} catch(e) {
alert('不支持 ActiveXObject');
return false;
}
var path = "c:/test.doc";
var wddoc = wdapp.documents.open(path);
// 插入
var range = wddoc.range(3, 10);
range.insertbefore('hello world!');
// 插入网页内容
var sel = div1.document.body.createTextRange();
sel.select();
div1.document.execCommand('Copy');
sel.moveEnd('character');
wdapp.selection.Paste();
// 替换
var keyword = "[title]";
var newstr = "这是标题";
wdapp.selection.find.execute(keyword, false, false, false, false, false, true, 1, true, newstr, 2);
}
</script>
<body>
<div id="div1">
<label style="background-color:yellow;">新内容</label>
</div>
<input type="button" name="submit" value="按钮" onclick="highlight()">
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>HighLight</title>
</head>
<script language="javascript">
function highlight(keyword){
var wdapp = null;
try {
wdapp = new ActiveXObject ("Word.Application");
wdapp.visible = true;
} catch(e) {
alert('不支持 ActiveXObject 或未安装 WORD');
return false;
}
var path = "c:/test.doc";
var wddoc = wdapp.documents.open(path);
wdapp.Selection.Find.Text = keyword;
while(wdapp.Selection.Find.Execute()){
wdapp.Selection.Range.Shading.BackgroundPatternColorIndex = 6;
}
}
</script>
<body>
<input type="button" name="submit" value="按钮" onclick="highlight('[title]')">
</body>
</html>