dedecms织梦内容管理系统    
首页 | java | C/C++ | PHP | 操作系统 | ajax | 脚本编程 | 安全技术 | 本站下载页 | flex | CRM | 专题 | QQ群 | 测试中心 | 会员中心 | 积分规则
  当前位置:主页>flex>文章内容
Flex 打印DataGrid内容
来源:http://www.cnblogs.com/mobile/archive/2007/01/24/6 作者:http://www.cnblogs.com/mobile/
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" 
    backgroundColor
="#FFFFFF" 
    fontFamily
="simsun" fontSize="12"
    paddingTop
="50" paddingBottom="50" paddingLeft="30" paddingRight="30" 
    height
="268" width="748">
    
<mx:Script>
        
<![CDATA[
            import mx.controls.DateField;
            import mx.core.*
            import mx.collections.ArrayCollection;
            import mx.printing.*;
            
            [Bindable]
            private var pageNumber:Number = 1;
            
            [Bindable]
            private var prodTotal:Number = 0;
            
            [Bindable]
            private var reportTitle:String = "报表标题";
            
            [Bindable]
            private var datetime:String = "";
            
            public static var footerHeight:Number = 20;
            public static var prodIndex:Number;
            public static var prodTotal:Number = 0;

            public static function doPrint(datap:Object,title:String,columns:Array):void {                
                var printJob:FlexPrintJob = new FlexPrintJob();
                if (printJob.start()) {                   
                    var thePrintView:FormPrintView = new FormPrintView();
                    Application.application.addChild(thePrintView);      
                    thePrintView.reportTitle = title;
                    thePrintView.datetime = mx.controls.DateField.dateToString(new Date(),"YYYY年MM月DD日");
                    thePrintView.printDataGrid.columns = columns;              
                    thePrintView.width=printJob.pageWidth;
                    thePrintView.height=printJob.pageHeight;                    
                    thePrintView.prodTotal = (datap as ArrayCollection).length; 
                    thePrintView.printDataGrid.dataProvider = datap;//设置数据v          
                    thePrintView.showPage("single");
                    if(!thePrintView.printDataGrid.validNextPage){
                        printJob.addObject(thePrintView);
                    }
                    else{
                        thePrintView.showPage("first");
                        printJob.addObject(thePrintView);
                        thePrintView.pageNumber++;
                        while(true){
                            thePrintView.printDataGrid.nextPage();
                            thePrintView.showPage("last");    
                            if(!thePrintView.printDataGrid.validNextPage) {
                                printJob.addObject(thePrintView);
                                break;
                            }
                            else{
                                thePrintView.showPage("middle");
                                printJob.addObject(thePrintView);
                                thePrintView.pageNumber++;
                            }
                        }
                    }
                    Application.application.removeChild(thePrintView);
                }
                printJob.send();
            }
            
            private function showPage(pageType:String):void {
                if(pageType == "first" || pageType == "middle") {
                    footer.includeInLayout=false;
                    footer.visible = false;
                }
                if(pageType == "middle" || pageType == "last") {
                    header.includeInLayout=false;
                    header.visible = false;
                }
                if(pageType == "last") {
                    // Show the footer.
                    footer.includeInLayout=true;
                    footer.visible = true;
                }
                //Update the DataGrid layout to reflect the results.
                validateNow();
            }        
        
]]>
    
</mx:Script>

    
<!-- The template for the printed page, with the contents for all pages. -->
    
<mx:VBox width="100%" horizontalAlign="left">
        
<mx:Label text="第 {pageNumber}页" color="#9e9e9e"/>
        
<mx:Label id="header" text="{reportTitle}" fontWeight="bold" fontSize="21" textAlign="center" width="100%"/>
        
<mx:HRule width="100%" height="1" strokeColor="#000000"/>
    
</mx:VBox>
    
    
<mx:PrintDataGrid id="printDataGrid" width="100%" height="100%" fontFamily="simsun" fontSize="12"/>
    
<mx:VBox width="100%" horizontalAlign="left" id="footer" >
        
<mx:Spacer height="100%"/>
        
<mx:HRule width="100%" height="1" strokeColor="#000000"/>
        
<mx:HBox width="100%">
            
<mx:Label text="记录总数:{prodTotal}"/>
            
<mx:Spacer width="100%"/>
            
<mx:Label text="打印日期:{datetime}"/>
        
</mx:HBox>
    
</mx:VBox>

</mx:VBox>
效果如 http://www.cnblogs.com/mobile/archive/2007/01/24/629603.html

上一篇:挑战最棒的留言本的源码(二)   下一篇:Java语言中Timer类的简洁用法
[收藏] [推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
用户名: 新注册) 密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论
  热点文章
·Flex中的闪烁效果
·flex: 使用setInterval 制作定时
·FLEX优秀开源项目介绍
·AS3中的正则表达式
·flex确认提示(confirm window)
·Flex RemoteObject类参考
·flex:RemoteObject 和 DataGrid
·AS3的面向对象特点概述
·利用AS3的图形界面开发及资源管
·AS3.0 访问属性
·AS3.0强大的事件机制
·FLASH CS3/AS3.0教程汇总(2007-7
  相关文章
·Flex中的闪烁效果
·flex: 使用setInterval 制作定时
·FLEX优秀开源项目介绍
·AS3中的正则表达式
·flex确认提示(confirm window)
·Flex RemoteObject类参考
·flex:RemoteObject 和 DataGrid
·AS3的面向对象特点概述
·利用AS3的图形界面开发及资源管
·AS3.0 访问属性
·AS3.0强大的事件机制
·FLASH CS3/AS3.0教程汇总(2007-7
  相关信息
copy right @ 百家拳软件项目研究室 2007 辽ICP备07011763