前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Flex 打印DataGrid内容 2.0

Flex 打印DataGrid内容 2.0

作者头像
用户3135539
发布2018-09-12 11:37:29
6020
发布2018-09-12 11:37:29
举报
文章被收录于专栏:
代码语言:javascript
复制
<?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>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2007-01-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云 BI
腾讯云 BI(Business Intelligence,BI)提供从数据源接入、数据建模到数据可视化分析全流程的BI能力,帮助经营者快速获取决策数据依据。系统采用敏捷自助式设计,使用者仅需通过简单拖拽即可完成原本复杂的报表开发过程,并支持报表的分享、推送等企业协作场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档