* @author zhu * @version 1.0 */ var baseVoListObj = function(){ this.volist = new Array(); this.cols = new Array(); this.widths = new Array(); }
var WordApp = function(wordTplPath){ var wordObj = new ActiveXObject("Word.Application"); if(wordObj==null){ alert( "不能创建Word对象!"); } wordObj.visible=false; this.wordObj = wordObj; this.docObj = this.wordObj.Documents.Open(getRootPath() + wordTplPath); }
WordApp.prototype.closeApp = function(){ if (this.wordObj !=null){ this.wordObj.Quit(); } }
WordApp.prototype.replaceBookmark = function(strName,content,type){ if (this.wordObj.ActiveDocument.BookMarks.Exists(strName)) { if (type != null && type == "pic") {//图片 var objDoc = this.wordObj.ActiveDocument.BookMarks(strName).Range.Select(); var objSelection = this.wordObj.Selection; objSelection.TypeParagraph(); //alert(getRootPath()+content); var objShape = objSelection.InlineShapes.AddPicture(getRootPath()+content); } else { this.wordObj.ActiveDocument.BookMarks(strName).Range.Select(); this.wordObj.Application.selection.Text = content; } }else{ //alert("标签不存在"); } }
WordApp.prototype.replaceBookmarkUsevo = function(voObj){ if(typeof voObj != "object"){ alert("请输入正确的vo对象"); }else{ for(var i in voObj){ this.replaceBookmark(i,voObj[i]); } } }
WordApp.prototype.replaceBookmarkUsepicvo = function(voObj){ if(typeof voObj !="object"){ alert("请输入正确的vo对象"); }else{ for(var i in voObj){ this.replaceBookmark(i,voObj[i],"pic"); } } }
WordApp.prototype.replaceBookmarkUsevolist = function(strName,voListObj){ if(typeof voListObj != "object"){ alert("参数应为数组类型"); }else{ var row = voListObj.volist.length; var col = voListObj.cols.length; var objDoc = this.wordObj.ActiveDocument.BookMarks(strName).Range; var objTable = this.docObj.Tables.Add(objDoc,row,col) ;//插入表格 for (var i = 0; i < row; i++) { for(var j=0; j
WordApp.prototype.getVoList = function (formName,arrayObj){//表单名,属性数组(可以为空) //var formArray = document.forms[formName]; var formArray = document.getElementsByName(formName); if (formArray != null) { if (arrayObj instanceof Array) { var voListObj = new baseVoListObj(); for(var i=0;i var vo = {}; for(var j=0;j if(formArray[i].elements[arrayObj[j]]!= undefined ){ eval("vo."+arrayObj[j]+" = formArray[i].elements[arrayObj[j]].value;"); if(i==0){//第一次的时候定义有效属性和宽度 voListObj.cols.push(arrayObj[j]); voListObj.widths.push(formArray[i].elements[arrayObj[j]].style.width); } } } voListObj.volist.push(vo); } return voListObj; }else{ var voListObj = new baseVoListObj(); for(var i=0;i var vo = {}; for(var j=0;j eval("vo."+formArray[i].elements[j].name+" = formArray[i].elements[j].value;"); if(i==0){//第一次的时候定义宽度 voListObj.cols.push(formArray[i].elements[j].name); voListObj.widths.push(formArray[i].elements[j].style.width); } } voListObj.volist.push(vo); } return voListObj; } }else{ return null; } }
function objToString(obj){ if(obj instanceof Array){ var str=""; for(var i=0;i str+="["; for(var j in obj[i]){ str+=j+"="+obj[i][j]+" "; } str+="]\n"; } return str; }else if(obj instanceof Object){ var str=""; for(var i in obj){ str+=i+"="+obj[i]+" "; } return str; } }
function getRootPath() { var location=document.location; if ("file:" == location.protocol) { var str = location.toString(); return str.replace(str.split("/").reverse()[0], ""); } var pathName=location.pathname.split("/"); return location.protocol+"//"+location.host+"/"+pathName[1]+"/"; } 先说到这里吧,以后有更好的再更新,希望对大家有用。
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn