我做的報表

這幾天晚上整理報表工具,做了一次測試,這是一個例子,大家看看怎麼樣,能更簡化嗎?功能還欠缺什麼?

 

這是數據項左側顯示

 

 

這是數據項上方顯示

 

相關程序

  private void testBuild() throws Exception {
    Result srcResult = buildTestSrcResult(5); // 隨機生成原始數據(5行)
    srcResult.setValue(0,4,null);//增加一個空值,檢驗空值的影響
    debug(srcResult);//顯示原始數據集

    ReportManager manager = new ReportManager();//報表生成類
    manager.setTdDefaultValue("width","66");//設置表格默認寬度,也可以用setDefaultValue實現
    manager.setDefaultValue(AttrItem.TABLE,"id","22222"); //設置表格的默認屬性
    manager.setIsLineColor2(true);//設置隔行顯示
    AttrItem item;
    manager.setTablePropertyValue("id","111"); //定義表格的id,這裏是

    manager.setDefaultValue(AttrItem.TEXT,AttrItem.NULL_VALUE,"---");//默認空值顯示字符串
    manager.setTdDefaultValue("nowrap","true");//設置表格默認屬性

    item = manager.addGroupItem(ReportManager.LEFT,0,0);//左邊按第0列分組,同時按第0列排序
    item.setTdPropertyValue("width",61);//本類數據的寬度
    item.setTdPropertyValue("bgcolor","#8800FF");//本類數據的背景色
    item.getHeadAttrItem().getDataProperty().setValue("地區");//設置標題
    item.getHeadAttrItem().setTdPropertyValue("bgcolor","#CC3366");//設置標題的背景

    item= manager.addHeadStatItem(ReportManager.LEFT,ReportManager.BEGIN_STAT,0,0,StatItem.STAT_TYPE_SUM,"合計");//增加合計,在開始位置
    item.getHeadAttrItem().getTdProperty().setPropertyValue("align","center");//設置格式
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#FF88FF");//設置背景

    item = manager.addGroupItem(ReportManager.LEFT,1,1);//左邊按第1列分組,同時按第1列排序
    item.getTdProperty().setPropertyValue("bgcolor","#8800FF");
    item.getHeadAttrItem().getDataProperty().setValue("員工");
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#009900");

    //上邊按第1列分組,同時按第1列排序----在第1層
    item = manager.addGroupItem(ReportManager.UP,2,2);
    item.getHeadAttrItem().getDataProperty().setValue("類別");
    item.getTdProperty().setPropertyValue("width",42);
    item.getTdProperty().setPropertyValue("bgcolor","#0088FF");
    item = manager.addGroupItem(ReportManager.UP,3,3);
    item.getHeadAttrItem().getDataProperty().setValue("月份");
   
    //上邊在第1層的第一個統計項
    item = manager.addHeadStatItem(ReportManager.UP,ReportManager.END_STAT,0,0,StatItem.STAT_TYPE_SUM,"小計");
    item.getTdProperty().setPropertyValue("bgcolor","#ff5555");
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#0000FF");//藍色

    //上邊在第1層的第2個統計項
    item = manager.addHeadStatItem(ReportManager.UP,ReportManager.END_STAT,0,1,StatItem.STAT_TYPE_SUM,"合計");
    item.getTdProperty().setPropertyValue("width",92);
    item.getTdProperty().setPropertyValue("bgcolor","#ff5555");
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#ccccFF");
    manager.addHeadStatItem(ReportManager.LEFT,ReportManager.BEGIN_STAT,1,0,StatItem.STAT_TYPE_SUM,"HJ");

    //上邊在第1層的第3個統計項
    item = manager.addHeadStatItem(ReportManager.UP,ReportManager.END_STAT,0,1,StatItem.STAT_TYPE_FORMULA,"合計公式");
    item.setFormula(new com.webrate.data.formula.RecordAdd2(0,-1,new Integer(1)));
    item.setDataPropertyValue(AttrItem.NULL_VALUE,"--");
    item.getDataProperty().setDoubleMaxScale(2);
    item.getTdProperty().setPropertyValue("bgcolor","#ff5555");
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#33ccFF");
   
    //上邊在第1層的第4、5個統計項,支持重複列
    item = manager.addHeadStatItem(ReportManager.UP,ReportManager.END_STAT,0,0,StatItem.STAT_TYPE_SUM,"XJ");
    item = manager.addHeadStatItem(ReportManager.UP,ReportManager.END_STAT,0,0,StatItem.STAT_TYPE_SUM,"XJ");

    // 定義第1個數據項
    item = manager.addDataItem(4,"數量");
    item.getTdProperty().setPropertyValue("width",51);
    item.getTdProperty().setPropertyValue("bgcolor","#ff8888");
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#4444FF");
    item.getDataProperty().setDoubleScale(1);
    // 定義第2個數據項
    item = manager.addDataItem(5,"金額");
    item.getDataProperty().setDisplayTag(AttrItem.INPUT_TEXT);// 標題同樣可以使用其它類型
    item.getDataProperty().setName("je");//變量名,生成後根據行和列得到類似je_1_2的名字
    item.getDataProperty().setDoubleScale(2);//小數位數
    item.getTdProperty().setPropertyValue("width",52);
    item.getDataProperty().setPropertyValue("size",12);//數據的屬性size=12
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#44FFCC");

    item = manager.addDataItem(-1,"公式");
    item.setFormula(new com.webrate.data.formula.RecordMul2(0,-2,-1));//左邊兩個數相乘
    item.getHeadAttrItem().getTdProperty().setPropertyValue("bgcolor","#4444FF");

    manager.addInitNode(ReportManager.LEFT,0,"上海1");//在左邊第0層強行增加一個分類項(沒有數據也顯示)
    manager.addInitNode(ReportManager.LEFT,0,"上海");//在左邊第0層強行增加一個分類項(沒有數據也顯示)
    //manager.setIsLeftData(true);//數據項在左側
   
    manager.buildNewResult(srcResult);//對結果集進行處理
    manager.spanNewResult();//對錶格區域的表格進行合併(規則略)
    debug(manager);//輸出
  }

    這個工具還能支持分頁顯示,也能生成更復雜的表格,這裏主要是展現不同區域可以設置不同的屬性。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章