把题库里面的试题导出成word的形式

这段代码展示了如何将题库中的试题导出为Word文档。首先,从session中获取数据,然后配置FreeMarker模板,创建文件并写入数据。最后,将文件路径保存到session,并返回下载流。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public String TiKuWord() throws Exception{

              System.out.println("aa"+aa);

              listzujuan=ses.FindzuJuan(aa);

              //listzujuan=ses.FindLianxi(aa);

              //System.out.println(listzujuan.get(0).getShtitle());

              Configuration configuration = newConfiguration();

              configuration.setDefaultEncoding("utf-8");

              // 模板放在com.canyou.template包下面,通过classpath装载

              configuration.setClassForTemplateLoading(Tb_sc_selectAction.class,

                            "/com/ecsystem/action");

              String zuzhuangcjr=(String) ActionContext.getContext().getSession().get("user");

              Template t =configuration.getTemplate("yyyy"+".ftl");// 设置要装载的模板

              String path =ServletActionContext.getServletContext().getRealPath("/paper");

               File file = new File(path);

               if(!file.exists()) { 

                      

                  file.mkdirs(); 

              } 

               

               long d=(new Date()).getTime();

               path=path+"\\"+zuzhuangcjr+d+".doc";

              File outFile = new File(path);

              if (!outFile.exists()) {

                     outFile.createNewFile();

              }

              Writer out = new BufferedWriter(newOutputStreamWriter(

                            new FileOutputStream(outFile),"utf-8"));

              Map map = new HashMap<String,Object>();

              map.put("rows", listzujuan);

              if(listzujuan!=null &&listzujuan.size()>0){

                     map.put("titless",aa);

              }

              t.process(map, out);             

              ActionContext.getContext().getSession().put("daochu","导出成功");

              ActionContext.getContext().put("daochu1","http://218.69.93.91:8090/ECSystem/paper/"+zuzhuangcjr+d+".doc");

              ActionContext.getContext().put("daochu2","点击下载");

              return SUCCESS;

       }

 

                         /**

                      * 注意:在下载的时候必须使用流的形式将其输出,注意文件的路径获取,

                      */

                    

                       File file = newFile("/"+downloadDir.trim()+"/" + d);

                         InputStream is = newFileInputStream(file);  //以流的形式输出文件信息

                         return is;


<script type="text/javascript">

function bao(s){

   if(s=="选择题"){

      document.getElementById("xzta").style.display='';

      document.getElementById("xztb").style.display='';

      document.getElementById("xztc").style.display='';

      document.getElementById("xztd").style.display='';

      var selectA = $.trim($("#selectA").val());

      var selectB = $.trim($("#selectB").val());

      var selectC = $.trim($("#selectC").val());

     

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值