关闭

J2EE 0.7.1—报表功能。传入封装数据的list实现打印标签报表。。

标签: 报表listexceptionstringnulliterator
1147人阅读 评论(1) 收藏 举报
分类:

代码
//传入list实现打印。推荐使用。方便快捷。   
protected void MingPrint(ActionMapping actionMapping,   
        ActionForm actionForm, HttpServletRequest httpServletRequest,   
        HttpServletResponse httpServletResponse, List list)   
        throws Exception {   
    BasicActionForm form = (BasicActionForm) actionForm;   
    String reportName = (String) form.getReservedProp("reportName");   
  
    if (reportName == null) {   
        throw new java.lang.UnsupportedOperationException(   
                "Reserved property 'reportName' not set yet!");   
    }   
    System.out.println("报表名称:"+reportName);   
    MREngine engine = null;   
    MRDataSet mrds = new MRDataSet();;   
       
    //ResultSet rs = DBTool.getResultSet(sql);   
    //if (rs == null) {   
    //  System.out.println("rs is null");   
    //}   
  
    try {   
        engine = new MREngine(httpServletRequest, httpServletResponse,   
                servlet.getServletContext());   
        engine.setRootPath("/Reports/");   
        // GBK字符集支持   
        engine.setUnicodeOption(1);   
    } catch (Exception e) {   
        System.err.println("根据数据集生成如意报表出错:" + e.getMessage());   
    }   
/System.out.println("传入的list="+list.toString());   
       
    int w = list.size();   
    int k ;   
    for( k=0; k < w; k++){   
        DataRecord  dataRecord = new DataRecord();   
        Map dataRecordMap = (Map)list.get(k);   
/System.out.println("dataRecordMap="+dataRecordMap.toString());   
        Iterator it = dataRecordMap.keySet().iterator();   
  
        while(it.hasNext()){   
               
            String columnName = it.next().toString();   
            //System.out.println(columnName);   
            Object obj = dataRecordMap.get(columnName);   
            dataRecord.setValue(columnName,obj);   
        }   
        mrds.addRow(dataRecord);   
    }   
       
    engine.addMRDataSet(reportName, mrds);   
    // engine.addMRDataSet(reportName, mrds);   
    engine.addReport(reportName);   
    byte[] mingData = engine.bind();   
/       System.out.println(mingData.length);   
    httpServletRequest.getSession().setAttribute("mingData", mingData);   
}  

Action中只需要一句:

java 代码
//一句搞定打印。   
this.MingPrint(mapping, form, request, response, userDao.findForListByName("user"));    

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:59588次
    • 积分:941
    • 等级:
    • 排名:千里之外
    • 原创:35篇
    • 转载:8篇
    • 译文:0篇
    • 评论:6条
    最新评论