码迷,mamicode.com
首页 > 其他好文 > 详细

风电平台导出功能

时间:2016-12-09 16:05:20      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:puts   序号   btn   his   else   port   平台   sheet   ica   

以质量保函为例

jsp文件:

添加导出按钮:

<a class="btn_short" name="button" id="button" href="javascript:void(0)" title="导出" onclick="QueryWlzxZlbhListUtils.jldc()">导出</a>

导出js:

<script type="text/javascript">;
  QueryWlzxZlbhListUtils = {};
  QueryWlzxZlbhListUtils.jldc = function() {
    $("query_wlzxZlbh_list_form").action = "wlzxZlbh/jlExport.do";
    Ext.milan.pagejs.page_wlzxZlbh.jldc(‘query_wlzxZlbh_list_form‘);
  };
</script>

 

 

pageJS文件:

Ext.milan.pagejs.page_wlzxZlbh.jldc = function(formId) {
  Milan.ajaxutility.downloadFile({form: $(formId) });
};

 

 

Action层文件:

public String jlExport() {
  WlzxZlbhQuery query = newQuery(WlzxZlbhQuery.class,DEFAULT_SORT_COLUMNS);
  try{
    reportStream = wlzxZlbhManager.jlExport(query);
    if(reportStream != null){
      String fileName = "质量保函.xls";
      this.filename = new String(fileName.getBytes(), "ISO8859-1");
      return "sjdc";
    }else{
      Map<String, Object> resInfo = null;
      resInfo = ResInfo.getResInfo("",false, false, 2, "无任何导出结果","");
      outXmlJson(resInfo);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}

 

 

 

Manager层文件:

public InputStream jlExport(WlzxZlbhQuery query) {
  List<WlzxZlbh> list = wlzxZlbhDao.jlExport(query);
  if(list != null && list.size()>0){
    ByteArrayOutputStream ops = genJlXls(list);
    InputStream ips = new ByteArrayInputStream(ops.toByteArray());
    return ips;
  }
  return null;
}

 

private ByteArrayOutputStream genJlXls(List<WlzxZlbh> list) {
  WritableWorkbook wwb;
  ByteArrayOutputStream ops = new ByteArrayOutputStream();
  try {
    wwb = Workbook.createWorkbook(ops);
    //设置单元格的文字格式
    WritableFont wf = new WritableFont(WritableFont.ARIAL,12,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
    WritableCellFormat wcf = new WritableCellFormat(wf);
    wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
    wcf.setAlignment(Alignment.CENTRE);
    //填充数据的内容
    Label label;
    WritableSheet sheet=wwb.createSheet("质量表函", 0);
    sheet.setColumnView(0,10);
    sheet.setColumnView(1,30);
    sheet.setColumnView(2,30);
    sheet.setColumnView(3,30);
    sheet.setColumnView(4,30);
    sheet.setColumnView(5,30);
    sheet.setColumnView(6,30);
    sheet.setColumnView(7,30);
    sheet.setColumnView(8,30);
    sheet.setColumnView(9,30);
    sheet.setColumnView(10,30);
    sheet.setColumnView(11,30);
    sheet.setColumnView(12,30);
    //创建表头
    //sheet.mergeCells(0,0,0,0);
    label = new Label(0,0,"序号",wcf);
    sheet.addCell(label);
    label = new Label(1,0,"供应商名称",wcf);
    sheet.addCell(label);
    label = new Label(2,0,"经办人",wcf);
    sheet.addCell(label);
    label = new Label(3,0,"应开保函日期",wcf);
    sheet.addCell(label);
    label = new Label(4,0,"收到保函日期",wcf);
    sheet.addCell(label);
    label = new Label(5,0,"函号",wcf);
    sheet.addCell(label);
    label = new Label(6,0,"保函签发日期",wcf);
    sheet.addCell(label);
    label = new Label(7,0,"保函生效日期",wcf);
    sheet.addCell(label);
    label = new Label(8,0,"保函失效日期",wcf);
    sheet.addCell(label);
    label = new Label(9,0,"保函金额",wcf);
    sheet.addCell(label);
    label = new Label(10,0,"保函退回时间",wcf);
    sheet.addCell(label);
    label = new Label(11,0,"保函退回原因",wcf);
    sheet.addCell(label);
    label = new Label(12,0,"状态",wcf);
    sheet.addCell(label);
    int i=0;
    for (WlzxZlbh zlbh : list){
      label = new Label(0,i+1,(i+1)+"",wcf); //序号
      sheet.addCell(label);
      label = new Label(1,i+1,zlbh.getGysmc(),wcf);
      sheet.addCell(label);
      label = new Label(2,i+1,zlbh.getJbrxm(),wcf);
      sheet.addCell(label);
      label = new Label(3,i+1,zlbh.getYkbhrqString(),wcf);
      sheet.addCell(label);
      label = new Label(4,i+1,zlbh.getSdbhrqString(),wcf);
      sheet.addCell(label);
      label = new Label(5,i+1,zlbh.getHh(),wcf);
      sheet.addCell(label);
      label = new Label(6,i+1,zlbh.getBhqfrqString(),wcf);
      sheet.addCell(label);
      label = new Label(7,i+1,zlbh.getBhsxrqString(),wcf);
      sheet.addCell(label);
      label = new Label(8,i+1,zlbh.getBhzfrqString(),wcf);
      sheet.addCell(label);

      //金额为数字,需转换为字符串输出
      label = new Label(9,i+1,zlbh.getBhje()+"",wcf);
      sheet.addCell(label);
      label = new Label(10,i+1,zlbh.getBhthsjString(),wcf);
      sheet.addCell(label);
      label = new Label(11,i+1,zlbh.getThyy(),wcf);
      sheet.addCell(label);

      //将数字格式的状态转换为文字
      String zt = "";
      if (zlbh.getZt() == 0){
        zt = "未处理";
      }else if (zlbh.getZt() == 1){
        zt = "完成";
      }else {
        zt = "已退回";
      }
      label = new Label(12,i+1,zt,wcf);
      sheet.addCell(label);
      i++;
    }
    wwb.write();
    wwb.close();
  } catch (IOException e){
    e.printStackTrace();
  } catch (RowsExceededException e){
    e.printStackTrace();
  } catch (WriteException e){
    e.printStackTrace();
  }
  return ops;
}

 

 

 

Dao层文件:

public List<WlzxZlbh> jlExport(WlzxZlbhQuery query) {
  String sql = "select t from WlzxZlbh t where 1=1 "
    + "/~ and t.gysmc = ‘[gysmc]‘ ~/"
    + "/~ and t.jbrxm = ‘[jbrxm]‘ ~/"
    + "/~ and t.ykbhrq = ‘[ykbhrq]‘ ~/"
    + "/~ and t.sdbhrq = ‘[sdbhrq]‘ ~/"
    + "/~ and t.hh = ‘[hh]‘ ~/"
    + "/~ and t.bhqfrq = ‘[bhqfrq]‘ ~/"
    + "/~ and t.bhsxrq = ‘[bhsxrq]‘ ~/"
    + "/~ and t.bhzfrq = ‘[bhzfrq]‘ ~/"
    + "/~ and t.bhje = ‘[bhje]‘ ~/"
    + "/~ and t.bhthsj = ‘[bhthsj]‘ ~/"
    + "/~ and t.thyy = ‘[thyy]‘ ~/"
    + "/~ order by [sortColumns] ~/";

  //搜索所有All
  return findHqlAll(sql,query);
}

 

 

xml配置文件:

//导出转换为流输出

<action name="wlzxZlbh/*" method="{1}" class="com.tech15.wlzx.action.WlzxZlbhAction">
  <result name="sjdc" type="stream">
    <param name="contentType">application/vnd.ms-excel</param>
    <param name="contentDisposition">attachment;filename="${filename}"</param>
    <param name="bufferSize">4096</param>
    <param name="inputName">reportStream</param>
  </result>
  <result name="*" type="direct">质量保函</result>
</action>

 

风电平台导出功能

标签:puts   序号   btn   his   else   port   平台   sheet   ica   

原文地址:http://www.cnblogs.com/ydd2ct/p/6149763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!