如题,上面让做个功能,让关键词在指定的WORD文档中高亮显示我知道用 Word.Application 可以插入内容,替换内容,但高亮怎么弄。。
改变背景颜色?怎么改?下面附上插入和替换的代码
<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>

解决方案 »

  1.   

    try
    sel.Font.Color= "#ff0000"
      

  2.   

    'Font'为空或不是对象能给出完整代码吗?
    对 Word.Application 实在不熟悉最好改背景颜色,字体颜色也能凑合
      

  3.   

    看看这个帖子对你有没有帮助
    http://topic.csdn.net/u/20100608/10/209d9c73-ccc7-44e4-9e1a-6198592eeec7.html
      

  4.   

    挣扎了几小时,效果是出来了
    但唉是一个一个替换的,求解决办法
    <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>
      

  5.   

    参考下,不知道有木有用:http://apps.hi.baidu.com/share/detail/6612136
      

  6.   

    神仙找你急事,请加我QQ182517061,是关于你这个帖子的回复的!http://topic.csdn.net/u/20080701/11/DE814029-0D5A-4A35-AE61-DA6D1F6ECFE4.html