iRepost打印报表

来源:互联网 发布:淘宝多长时间自动收货 编辑:程序博客网 时间:2024/05/16 18:41

1.iReport是个工具 首先要安装到你要用到的项目中

然后在*.jrxml文件中进行设计 他会自动生成一个*.jasper文件

/*
  * 月度考核报表
  */
 public ActionForward monthExam(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  log.info("Enter monthExam");
  // 第一步: 准备好报表设计文件名 注意不要后缀名
  request.setAttribute(Constants.REPORT_FILE_KEY, "monthLists");// 报表的文件名
  // 第二步: 准备好报表的数据(查询数据)
  String sname = request.getParameter("sname");// 所属部门
  String startTime = request.getParameter("startTime");// 开始时间
  String endTime = request.getParameter("endTime");// 结束时间
  String sid = request.getParameter("sid");// 科室id
  String month = request.getParameter("month");
  List<AttendanceVO> list = this.attendSer.printMonthCheck(month, sid,
    sname, startTime, endTime);
  if (list != null && list.size() > 0) {
   for (AttendanceVO a : list) {
    if (a.getYi() == null) {
     a.setYi("");
    } 

   }
  } else {
   AttendanceVO attendance = new AttendanceVO();

   attendance.setMonth(startTime.substring(0, 4) + "年" + month + "月份");
   attendance.setSname(sname);
   list.add(attendance);
  }
  request.setAttribute(Constants.REPORT_DATAS_KEY, list);
  // 第三步:准备好报表参数
  HashMap maps = new HashMap();
  request.setAttribute(Constants.REPORT_PARAMS_KEY, maps);
  // 第四步:选择报表格式 html/excel/pdf/word/txt/xml 默认是xml格式
  String style = request.getParameter("style");
  if ("html".equalsIgnoreCase(style)) {
   return mapping.findForward("reportToHtml");
  } else if ("pdf".equalsIgnoreCase(style)) {
   return mapping.findForward("reportToPdf");
  } else {
   return mapping.findForward("reportToExcel3");
  }

 

 

通用的报表类

原创粉丝点击