当前位置:软件学习 > Word >>

jqurey异步导出word

在页面上填写值,然后导出到word模板中,并把页面上的值带到模板中,也就是导出word文档,提前有word 的模板形式,

1.jsp 页面

 

<table class="formTable"> 
      <TR> 
        <TD class="label">会议地点</TD> 
        <TD class="content"> 
        <INPUT id="meetingSite"  type="text" class="text" name="CommonLink/meetingSite"></TD> 
        <TD class="label">会议人员</TD> 
        <TD> 
        <INPUT id="meetingPerson" type="text" class="text" name="CommonLink/meetingPerson"></TD> 
    </TR> 
    <TR> 
        <TD class="label">会议内容</TD> 
        <TD class="content"> 
        <INPUT id="meetingContent"  type="text" class="text" name="CommonLink/meetingContent"></TD> 
        <TD class="label">会议时间</TD> 
        <TD><INPUT id="meetingDate" type="text" class="text" name="CommonLink/meetingDate"></TD> 
    </TR> 
    <TR> 
        <TD class="label">总经理</TD> 
        <TD class="content"> 
        <INPUT id="manager"  type="text" class="text" name="CommonLink/manager"></TD> 
        <TD class="label">采购部门</TD> 
        <TD><INPUT id="purchaseDep"  type="text" class="text" name="CommonLink/purchaseDep"></TD> 
    </TR>      
   </table> 
<div id="btns" class="form-btns">    
<INPUT value="导出word文档" type="button" class="btn" onclick="exportWord();">     
 </div> 

   <table class="formTable">
       <TR>
   <TD class="label">会议地点</TD>
   <TD class="content">
   <INPUT id="meetingSite"  type="text" class="text" name="CommonLink/meetingSite"></TD>
   <TD class="label">会议人员</TD>
   <TD>
   <INPUT id="meetingPerson" type="text" class="text" name="CommonLink/meetingPerson"></TD>
  </TR>
  <TR>
   <TD class="label">会议内容</TD>
   <TD class="content">
   <INPUT id="meetingContent"  type="text" class="text" name="CommonLink/meetingContent"></TD>
   <TD class="label">会议时间</TD>
   <TD><INPUT id="meetingDate" type="text" class="text" name="CommonLink/meetingDate"></TD>
  </TR>
  <TR>
   <TD class="label">总经理</TD>
   <TD class="content">
   <INPUT id="manager"  type="text" class="text" name="CommonLink/manager"></TD>
   <TD class="label">采购部门</TD>
   <TD><INPUT id="purchaseDep"  type="text" class="text" name="CommonLink/purchaseDep"></TD>
  </TR>  
    </table>
 <div id="btns" class="form-btns">  
 <INPUT value="导出word文档" type="button" class="btn" onclick="exportWord();">  
  </div>

 

2.导出用异步的方法

[html] 
function exportWord(){ 
    var data = setData(); 
    jQuery.post("http://localhost:8080/expWord/GKBX29_word.jsp",data,function(data1){ 
        var url = data1; //回调函数,返回值是地址,data1         
        window.open(url); //打开 
    }); 

function setData(){ 
    var data = {}; 
    data.author='zzz'; 
    data.meetingSite = document.getElementById("meetingSite").value;  
    data.purchaseDep = document.getElementById("purchaseDep").value;  
    data.meetingPerson = document.getElementById("meetingPerson").value;  
    data.meetingContent = document.getElementById("meetingContent").value;  
    data.meetingDate = document.getElementById("meetingDate").value;  
    data.manager = document.getElementById("manager").value;         
    return data; 

function exportWord(){
 var data = setData();
 jQuery.post("http://localhost:8080/expWord/GKBX29_word.jsp",data,function(data1){
  var url = data1; //回调函数,返回值是地址,data1  
  window.open(url); //打开
 });
}
function setData(){
 var data = {};
 data.author='zzz';
 data.meetingSite = document.getElementById("meetingSite").value;
 data.purchaseDep = document.getElementById("purchaseDep").value;
 data.meetingPerson = document.getElementById("meetingPerson").value;
 data.meetingContent = document.getElementById("meetingContent").value;
 data.meetingDate = document.getElementById("meetingDate").value;
 data.manager = document.getElementById("manager").value;   
 return data;
}
3.GKBX29_word.jsp其实是后台的处理方法,因为本次开发用EOS,所以在jsp用request接收值,并传递到模板


[html] 
<%@page import="java.util.HashMap"%> 
<%@page import="java.util.Map"%> 
<%@page import=&quo

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,