浏览 3367 次
锁定老帖子 主题:导出到word,并产生目录
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-04-30
var oWord = new ActiveXObject("Word.Application"); var oDoc = oWord.Documents.Add("",0,1); var strFields = form.elements["gFields"].value; var fields = strFields.split(","); oWord.Selection.TypeParagraph(); oWord.Selection.Style = oDoc.Styles("正文"); var wdPageBreak = 7; oWord.Selection.InsertBreak(wdPageBreak); //生成下一页,用于产生正文部分。当前页用于生成目录 for(var i=0;i<fields.length;i++){ form.elements["gFields"].value = fields[i]; var oRange = oWord.Selection.Range; pastObj(servlet,form,oWord); } oWord.Selection.TypeBackspace(); //去掉最后一页 oWord.Selection.HomeKey(6); //返回首页的第一行 oWord.Selection.Font.Bold = 9999998; //加粗 oWord.Selection.Font.Size = 16; //设置字体大小(3号) oWord.Selection.TypeText("目录"); oWord.Selection.ParagraphFormat.Alignment = 1; //居中 oWord.Selection.TypeParagraph(); //换行 oWord.Selection.Style = oDoc.Styles("正文"); //样式设为正文 oWord.Application.WindowState = 2; oWord.Application.WindowState = 0; //生成目录 oWord.ActiveDocument.TablesOfContents.add(oWord.Selection.Range,true,1,3,false,"",true,true,"",true,true,true); oWord.ActiveDocument.TablesOfContents(1).TabLeader = 1 oWord.ActiveDocument.TablesOfContents.Format = 0; oWord.Selection.Sections(1).Footers(1).PageNumbers.Add(2,true); //在页脚出生成页码 oWord.Application.Visible = true; //退出word //oWord.Quit(); oWord = null; } function pastObj(servlet, form,oWord){ var ajax = new AJAXInteraction(servlet, function(requestText) { if (requestText == "FAILED") { return; } else { var oDoc = oWord.ActiveDocument; var sele = oWord.Selection; sele.Style = oDoc.Styles("标题 1"); //设置样式为标题1 var tempObj = document.getElementById("content"); tempObj.innerHTML = requestText; var title = document.getElementById("title_"+form.elements["gFields"].value).value; oWord.Selection.TypeText(title); //取得单位名称,并设为标题 sele.TypeParagraph(); //换行 sele.Style = oDoc.Styles("正文"); //设置样式为正文 var arrs = requestText.split("^^^"); for(var i=0;i<arrs.length;i++){ var obj = document.getElementById("content"); obj.innerHTML = arrs[i]; var sel = document.body.createTextRange(); sel.moveToElementText(obj); sel.select(); sel.execCommand("Copy"); sele.paste(); var wdPageBreak = 7; sele.InsertBreak(wdPageBreak); //生成下一页 } //sele.TypeParagraph(); //sele.TypeText("测试1"); //sele.Style = oDoc.Styles("正文"); } }); ajax.doPost(getRequestBody(form)); } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-12-26
好东西,收藏.谢谢楼主
|
|
返回顶楼 | |