<script type="text/javascript">
var xmlHttpRequest;
//实例化XMLHTTPREQUEST
function getXMLHttpRequest(){
if(window.XMLHttpReqeust){
xmlHttpRequest=new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
}
//生成期刊 :向服务器请求获取将要存取的内容
function doBuildPeriodical(){
var fileGuid=pids();
var url="buildPeriodicalServlet?";
getXMLHttpRequest();
xmlHttpRequest.open("POST",url,true);
xmlHttpRequest.setRequestHeader("content-type","application/x-www-form-urlencoded");
xmlHttpRequest.onreadystatechange=callBack;
xmlHttpRequest.send("fileGuid="+fileGuid);
exprotWord();
}
//取得所有的附件ID 这里是附件。
function pids(){
var text=document.getElementsByName("fileGuid");
var pids="";
for(var i=0;i<text.length;i++){
if(i==text.length-1){
pids=pids+text[i].value;
}else{
pids=pids+text[i].value+",";
}
}
return pids;
}
//XMLHTTPREQUEST的回调函数
function callBack(){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
document.getElementById("content").value=xmlHttpRequest.responseText;
}
}
}
function exprotWord(){
var wordApp=new ActiveXObject("Word.Application");
wordApp.Visible=true;
//打开指定的WORD文档
var wordDoc=wordApp.Documents.Open("d:\cc.doc");
var selection=wordApp.Selection;
//调用下面的方法 第二个参数是要替换的内容,第三个参数是新内容
replaceText(selection,"yearPMaxNo","${result.yearPMaxNo}")
replaceText(selection,"sumMaxNo","${result.sumMaxNo}");
replaceText(selection,"editUnit","{result.editUnit}");
replaceText(selection,"createDate","${result.createDate}");
var content=document.getElementById("content").value;
replaceText(selection,"filecontent",content);
replaceText(selection,"dutyEditName","${result.dutyEditName}");
replaceText(selection,"dutyEditPhone","${result.dutyEditPhone}");
replaceText(selection,"dutyEditEmail","${result.dutyEditEmail}");
replaceText(selection,"submitUnit","${result.submitUnit}");
}
function replaceText(Selection,oldText,newText){
Selection.Find.Text=oldText;
Selection.Find.wrap=1;
if(newText==""){
newText=" ";
}
while(Selection.Find.Execute()){
Selection.TypeText(newText);
}
}
</script>