您的位置:首页 > Web前端 > JavaScript

javascript操作word

2009-10-13 16:58 134 查看
<script language="javascript">

function outDoc(filename){

var wdapp=new ActiveXObject("Word.Application");

wdapp.visible=true;

wddoc=wdapp.Documents.Open(filename); //打开指定的文档
var myElement;
var numberOfControls=document.test.length;

for(var i=0;i<numberOfControls;i++)
{
myElement=document.test[i];
if(myElement.type=="checkbox")
{
if(myElement.checked==true)
{

if(myElement.value=="船舶"){
wdapp.Selection.GoTo(-1,0,0,"船舶");
wdapp.Selection.InsertSymbol(-3843,"Wingdings",true);
}
if(myElement.value=="海洋工程"){
wdapp.Selection.GoTo(-1,0,0,"海洋工程");
wdapp.Selection.InsertSymbol(-3843,"Wingdings",true);
}
if(myElement.value=="船用产品"){
wdapp.Selection.GoTo(-1,0,0,"船用产品");
wdapp.Selection.InsertSymbol(-3843,"Wingdings",true);
}
if(myElement.value=="ISM认证"||myElement.value=="ISPS认证"){

wdapp.Selection.GoTo(-1,0,0,"ISMISPS认证");
wdapp.Selection.InsertSymbol(-3843,"Wingdings",true);
}
}else{
var certifyCount=1;
if(myElement.value=="船舶"){
wdapp.Selection.GoTo(-1,0,0,"船舶");
wdapp.Selection.InsertSymbol(-3985,"Wingdings",true);
}
if(myElement.value=="海洋工程"){
wdapp.Selection.GoTo(-1,0,0,"海洋工程");
wdapp.Selection.InsertSymbol(-3985,"Wingdings",true);
}
if(myElement.value=="船用产品"){
wdapp.Selection.GoTo(-1,0,0,"船用产品");
wdapp.Selection.InsertSymbol(-3985,"Wingdings",true);
}
if(myElement.value=="ISM认证"||myElement.value=="ISPS认证"){
certifyCount=certifyCount-1;
if(certifyCount==1){
wdapp.Selection.GoTo(-1,0,0,"ISMISPS认证");
wdapp.Selection.InsertSymbol(-3985,"Wingdings",true);
}
}

}
}
}

//wddoc.Application.Printout();

wdapp=null;

}

这是对应的word的宏

Sub slmtest()
'
' slmtest Macro
'
Selection.GoTo What:=wdGoToBookmark, Name:="checkbox2"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.InsertSymbol Font:="Wingdings", CharacterNumber:=-3843, Unicode _
:=True
End Sub

插入的字符是一个特殊字符charmap中Wingdings中0xFD对应的字符

其中用到了word中插入选项卡中书签的作用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: