flex的grid控件结合repeater控件可以用来生成不规则报表。下面是一个简单的例子:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" fontSize="13" creationComplete="init()">
?<mx:Script>
??<![CDATA[
???import mx.collections.ArrayCollection;
????import mx.containers.*;
?? ?import mx.controls.Alert;
?? ?import mx.controls.Label;
???private var astInfo:AssetStatInfo=null;
???private function init():void{
???......//从数据库获取数据,略
???}
???
???private var arr:ArrayCollection=new ArrayCollection();
???private function fresh(backInfo:AssetStatInfo,obj:Object):void{
????astInfo=backInfo;
????arr.removeAll();
//col1span:18表示该行第一列跨18行,col2span:2,表示该行第2列跨2行
????arr.addItem({col1span:18,type:"硬件类",catelog:"PC机",name:astInfo.totalStatData.zmwj.name,num:astInfo.totalStatData.zmwj.num,total:astInfo.totalStatData.zmwj.price});
????arr.addItem({col1span:0,col2span:0,type:"",catelog:"",name:astInfo.totalStatData.bjbdl.name,num:astInfo.totalStatData.bjbdl.num,total:astInfo.totalStatData.bjbdl.price});
????arr.addItem({col1span:0,col2span:3,catelog:"辅助设备",name:astInfo.totalStatData.dyj.name,num:astInfo.totalStatData.dyj.num,total:astInfo.totalStatData.dyj.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.smy.name,num:astInfo.totalStatData.smy.num,total:astInfo.totalStatData.smy.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.fzsbqt.name,num:astInfo.totalStatData.fzsbqt.num,total:astInfo.totalStatData.fzsbqt.price});
????arr.addItem({col1span:0,catelog:"服务器",name:astInfo.totalStatData.xxj.name,num:astInfo.totalStatData.xxj.num,total:astInfo.totalStatData.xxj.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.wjfwq.name,num:astInfo.totalStatData.wjfwq.num,total:astInfo.totalStatData.wjfwq.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.fwqqt.name,num:astInfo.totalStatData.fwqqt.num,total:astInfo.totalStatData.fwqqt.price});
????arr.addItem({col1span:0,col2span:4,catelog:"存储设备",name:astInfo.totalStatData.cpzl.name,num:astInfo.totalStatData.cpzl.num,total:astInfo.totalStatData.cpzl.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.cdk.name,num:astInfo.totalStatData.cdk.num,total:astInfo.totalStatData.cdk.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.ccjhj.name,num:astInfo.totalStatData.ccjhj.num,total:astInfo.totalStatData.ccjhj.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.ccsbqt.name,num:astInfo.totalStatData.ccsbqt.num,total:astInfo.totalStatData.ccsbqt.price});
????arr.addItem({col1span:0,catelog:"网络设备",name:astInfo.totalStatData.jhj.name,num:astInfo.totalStatData.jhj.num,total:astInfo.totalStatData.jhj.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.lyq.name,num:astInfo.totalStatData.lyq.num,total:astInfo.totalStatData.lyq.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.wlsbqt.name,num:astInfo.totalStatData.wlsbqt.num,total:astInfo.totalStatData.wlsbqt.price});
????arr.addItem({col1span:0,catelog:"安全设备",name:astInfo.totalStatData.fhq.name,num:astInfo.totalStatData.fhq.num,total:astInfo.totalStatData.fhq.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.idsIps.name,num:astInfo.totalStatData.idsIps.num,total:astInfo.totalStatData.idsIps.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.aqsbqt.name,num:astInfo.totalStatData.aqsbqt.num,total:astInfo.totalStatData.aqsbqt.price});
????arr.addItem({col1span:9,type:"软件类",catelog:"系统软件",name:astInfo.totalStatData.sjk.name,num:astInfo.totalStatData.sjk.num,total:astInfo.totalStatData.sjk.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.zjj.name,num:astInfo.totalStatData.zjj.num,total:astInfo.totalStatData.zjj.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.xtrjqt.name,num:astInfo.totalStatData.xtrjqt.num,total:astInfo.totalStatData.xtrjqt.price});
????arr.addItem({col1span:0,col2span:6,catelog:"关键应用系统",name:astInfo.totalStatData.yxglxt.name,num:astInfo.totalStatData.yxglxt.num,total:astInfo.totalStatData.yxglxt.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.rlzyglxt.name,num:astInfo.totalStatData.rlzyglxt.num,total:astInfo.totalStatData.rlzyglxt.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.cwglxt.name,num:astInfo.totalStatData.cwglxt.num,total:astInfo.totalStatData.cwglxt.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.zcglxt.name,num:astInfo.totalStatData.zcglxt.num,total:astInfo.totalStatData.zcglxt.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.zhglxt.name,num:astInfo.totalStatData.zhglxt.num,total:astInfo.totalStatData.zhglxt.price});
????arr.addItem({col1span:0,name:astInfo.totalStatData.xtbgxt.name,num:astInfo.totalStatData.xtbgxt.num,total:astInfo.totalStatData.xtbgxt.price});
????repeat.dataProvider=arr;
????var row:GridRow;
????for(i=0;i<arr.length;i++){
?????row=GridRow(content.getChildAt(i+1));
?????if(arr[i]["col1span"]>0){
??????GridItem(row.getChildAt(0)).rowSpan=arr[i]["col1span"];
?????}else{
??????row.removeChildAt(0);
?????}
?????if(arr[i]["col2span"]>0){
??????if(arr[i]["col1span"]==0){
???????GridItem(row.getChildAt(0)).rowSpan=arr[i]["col2span"];
??????}else{
???????GridItem(row.getChildAt(1)).rowSpan=arr[i]["col2span"];
??????}
?????}else{
??????row.removeChildAt(0);
?????}
????}
???}
??]]>
?</mx:Script>
?<mx:Canvas width="100%" height="100%" backgroundColor="#FFFFFF" horizontalScrollPolicy="off">
??<mx:VBox? width="98%" height="100%">
???<mx:Label text="IT资产统计总表" width="100%" fontSize="24" top="10" textAlign="center" fontWeight="bold" />
???<mx:Grid width="100%" height="100%" horizontalGap="0" verticalGap="0" borderStyle="solid" borderColor="#000000" id="content">
????<mx:GridRow width="100%" height="25" >
?????<mx:GridItem borderStyle="solid" borderColor="#000000" verticalAlign="middle" horizontalAlign="left" width="15%">
??????<mx:Label text="IT资产类别" width="100%" textAlign="left" fontWeight="bold" />
?????</mx:GridItem>
?????<mx:GridItem borderStyle="solid" borderColor="#000000" colSpan="2" verticalAlign="middle" horizontalAlign="left" width="15%">
??????<mx:Label text="类别大项" width="100%" textAlign="left" fontWeight="bold" />
?????</mx:GridItem>
?????<mx:GridItem borderStyle="solid" borderColor="#000000" colSpan="2" verticalAlign="middle" horizontalAlign="left" width="40%">
??????<mx:Label text="类别细分" width="100%" textAlign="left" fontWeight="bold"/>
?????</mx:GridItem>
?????<mx:GridItem borderStyle="solid" borderColor="#000000" verticalAlign="middle" horizontalAlign="center" width="15%">
??????<mx:Label text="资产数量" width="100%" textAlign="center" fontWeight="bold"/>
?????</mx:GridItem>
?????<mx:GridItem borderStyle="solid" borderColor="#000000" colSpan="2" verticalAlign="middle" horizontalAlign="center" width="15%">
??????<mx:Label text="资产价值" width="100%" textAlign="center" fontWeight="bold"/>
?????</mx:GridItem>
????</mx:GridRow>
????<mx:Repeater id="repeat">
?????<mx:GridRow width="100%" height="25" >
??????<mx:GridItem borderStyle="solid" borderColor="#000000" verticalAlign="middle" horizontalAlign="left">
???????<mx:Label text="{repeat.currentItem.type}"? width="100%" textAlign="left" fontWeight="bold" />
??????</mx:GridItem>
??????<mx:GridItem borderStyle="solid" borderColor="#000000" colSpan="2" verticalAlign="middle" horizontalAlign="left">
???????<mx:Label text="{repeat.currentItem.catelog}"? width="100%" textAlign="left" fontWeight="bold" />
??????</mx:GridItem>
??????<mx:GridItem borderStyle="solid" borderColor="#000000" colSpan="2" verticalAlign="middle" horizontalAlign="left">
???????<mx:Label text="{repeat.currentItem.name}" width="100%" textAlign="left" fontWeight="bold"/>
??????</mx:GridItem>
??????<mx:GridItem borderStyle="solid" borderColor="#000000" verticalAlign="middle" horizontalAlign="center">
???????<mx:Label text="{repeat.currentItem.num}" width="100%" textAlign="center" fontWeight="bold"/>
??????</mx:GridItem>
??????<mx:GridItem borderStyle="solid" borderColor="#000000" colSpan="2" verticalAlign="middle" horizontalAlign="center">
???????<mx:Label text="{repeat.currentItem.total}" width="100%" textAlign="center" fontWeight="bold"/>
??????</mx:GridItem>
?????</mx:GridRow>
????</mx:Repeater>
???</mx:Grid>
???
??</mx:VBox>
??
?</mx:Canvas>
</mx:Application>
解决问题的思路:先构造规则表结构的数据集,然后用repeater控件生成所有行,最后对需要处理的行进行合并。