打印报表

PrintDataGrid.mxml

<?xml version="1.0"?>
<!-- printing\DGPrintCustomComp.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    height
="450" 
    width
="550">

    
<mx:Script>
        
<![CDATA[
            import mx.printing.FlexPrintJob;
            import MyPrintView;

            public function doPrint():void {
                // Create a FlexPrintJob instance.
                var printJob:FlexPrintJob = new FlexPrintJob();
    
                // Start the print job.
                if(printJob.start()) {
                    // Create a MyPrintView control as a child 
                    // of the current view.
                    var formPrintView:MyPrintView = new MyPrintView();
                    addChild(formPrintView);
    
                    // Populate the print control's contact label 
                    // with the text from the form's name, 
                    // phone, and e-mail controls.
                    formPrintView.contact.text = 
                        "Contact: " + custName.text + "  " +
                        custPhone.text + "  " + custEmail.text;
    
                    // Set the print control's data grid data provider to be 
                    // the displayed data grid's data provider.
                    formPrintView.myDataGrid.dataProvider = 
                        myDataGrid.dataProvider;
    
                    // Add the SimplePrintview control to the print job.
                    // For comparison, try setting the 
                    // second parameter to "none".
                    printJob.addObject(formPrintView);
    
                    // Send the job to the printer.
                    printJob.send();
    
                    // Remove the print-specific control to free memory.
                    removeChild(formPrintView);
                }
            }
        
]]>
    
</mx:Script>

    
<!-- The form to display-->
    
<mx:Form id="myForm">
        
<mx:FormHeading label="Contact Information"/>
        
<mx:FormItem label="Name: ">
            
<mx:TextInput id="custName" 
                width
="200" 
                text
="Samuel Smith"
                fontWeight
="bold"/>
        
</mx:FormItem>
        
<mx:FormItem label="Phone: ">
            
<mx:TextInput id="custPhone" 
                width
="200" 
                text
="617-555-1212"
                fontWeight
="bold"/>
        
</mx:FormItem>
        
<mx:FormItem label="Email: ">
            
<mx:TextInput id="custEmail" 
                width
="200" 
                text
="sam@sam.com"
                fontWeight
="bold"/>
        
</mx:FormItem>

        
<mx:FormHeading label="Product Information"/>
        
<mx:DataGrid id="myDataGrid" width="300">
            
<mx:dataProvider>
                
<mx:Object Product="Flash" Code="1000"/>
                
<mx:Object Product="Flex" Code="2000"/>
                
<mx:Object Product="ColdFusion" Code="3000"/>
                
<mx:Object Product="JRun" Code="4000"/>
            
</mx:dataProvider>
        
</mx:DataGrid>
        
<mx:Button id="myButton" 
            label
="Print" 
            click
="doPrint();"/>
    
</mx:Form>
</mx:Application>


//////////////////////////////
MyPrintView.mxml

<?xml version="1.0"?>
<!-- printing\myComponents\MyPrintView.mxml -->
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" 
    backgroundColor
="#FFFFFF" 
    height
="250" width="450" 
    paddingTop
="50" paddingLeft="50" paddingRight="50">

    
<!-- The controls to print, a label and a PrintDataGrid control. -->
    
<mx:Label id="contact"/>
    
<mx:PrintDataGrid id="myDataGrid" width="100%">
        
<mx:columns>
            
<mx:DataGridColumn dataField="Product"/>
            
<mx:DataGridColumn dataField="Code"/>
        
</mx:columns>
    
</mx:PrintDataGrid>
</mx:VBox>


/////////总结/////////////
1. validateNow();//组件立即更新
2.自定义的组件使用就像对象一样 import进来,再新建对象或是用标签

posted @ 2007-03-02 10:39  fishert  阅读(385)  评论(0编辑  收藏  举报