0

我需要帮助打印我的高级数据网格。我尝试了不同的方法,但我得到的只是一张空白表。

该表在那里,但其中没有标题或数据。这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" width="95%" height="95%" fontFamily="Arial" fontSize="12">
    <fx:Script>
        <![CDATA[
            import valueObjects.SummaryCollectionsDeposits;

            [Bindable]
            public var report:Object;
            [Bindable]
            public var scdno:String;
            [Bindable]
            public var pageNumber:Number = 1;

            public function showPage(pageType:String):void {

            }

            private function getReceiptNumber(o:Object, column:AdvancedDataGridColumn) {
                return o.receipt.receiptNumber;
            }

            private function getPayor(o:Object, column:AdvancedDataGridColumn) {
                return o.receipt.payor;
            }
            private function getParticular(o:Object, column:AdvancedDataGridColumn) {
                if(o.natureOfCollection.accountTitle=="Others")
                    return o.description;
                else
                    return o.natureOfCollection.accountTitle;

            }
            private function getBrgyAmount(o:Object, column:AdvancedDataGridColumn) {
                return Currency.format(o.amount);
            }
            private function getGridDate(o:Object, column:AdvancedDataGridColumn) {
                return gridDateFormat.format(o.receipt.receiptDate);
            }

            private function getBrgyDeposites(o:Object, column:AdvancedDataGridColumn) {
                if(o.natureOfCollection.accountTitle=="Others")
                    return Currency.format(o.amount);
                else
                    return "";

            }
            private function getBrgyBalance(o:Object, column:AdvancedDataGridColumn) {
                if(o.natureOfCollection.accountTitle=="Others")
                    return "";
                else
                    return Currency.format(o.amount);

            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <mx:DateFormatter id="gridDateFormat" formatString="MM/DD/YY"/>
        <mx:DateFormatter id="dateFormat" formatString="MMMM DD, YYYY"/>
        <mx:CurrencyFormatter id="Currency" precision="2" rounding="none" decimalSeparatorTo="." thousandsSeparatorTo=","
                              useThousandsSeparator="true" currencySymbol="" useNegativeSign="true"/>   </fx:Declarations>

    <s:layout>
        <s:VerticalLayout verticalAlign="top" horizontalAlign="center" >

        </s:VerticalLayout>
    </s:layout>

    <s:Group width="100%" id="header">
        <s:layout>
            <s:VerticalLayout verticalAlign="top" horizontalAlign="center" >

            </s:VerticalLayout>
        </s:layout>
        <s:Group  width="100%">
            <s:layout>
                <s:VerticalLayout horizontalAlign="center"/>

            </s:layout>

            <s:Label text="{report.TITLE}" fontWeight="bold" fontSize="14"/>
            <s:Label text="for {dateFormat.format(report.reportDate)}"/>
        </s:Group>
        <mx:HRule width="100%"/>

    </s:Group>

    <mx:PrintAdvancedDataGrid dataProvider="{report.collections}"
                         width="100%"  id="adg" height="{adg.measureHeightOfItems(0, report.collections.length) + adg.headerHeight}"
                         designViewDataType="flat" allowInteraction="true" >

        <mx:groupedColumns>
            <mx:AdvancedDataGridColumn headerText="Date"  wordWrap="true" labelFunction="getGridDate"/>
            <mx:AdvancedDataGridColumn  headerText="OR/VDS/SCR No" labelFunction="getReceiptNumber" wordWrap="true"/>
            <mx:AdvancedDataGridColumn  headerText="Payor/Bank" labelFunction="getPayor" wordWrap="true"/>
            <mx:AdvancedDataGridColumn  headerText="Particulars" labelFunction="getParticular" wordWrap="true"/>
            <mx:AdvancedDataGridColumnGroup headerText="Barangay">
                <mx:AdvancedDataGridColumn  headerText="Collections" labelFunction="getBrgyAmount" textAlign="right" />
                <mx:AdvancedDataGridColumn  headerText="Deposits" textAlign="right" labelFunction="getBrgyDeposites"/>
                <mx:AdvancedDataGridColumn  headerText="Balance" textAlign="right" labelFunction="getBrgyBalance"/>
            </mx:AdvancedDataGridColumnGroup>
            <mx:AdvancedDataGridColumnGroup headerText="As Deputized by City/Municipality">
                <mx:AdvancedDataGridColumn headerText="Collections" textAlign="right" />
                <mx:AdvancedDataGridColumn  headerText="Deposits" textAlign="right"/>
                <mx:AdvancedDataGridColumn  headerText="Balance" textAlign="right"/>
            </mx:AdvancedDataGridColumnGroup>
        </mx:groupedColumns>

    </mx:PrintAdvancedDataGrid >


</s:Group>

这是我在主代码中的打印功能:

private function doPrint():void {

                var printJob:FlexPrintJob = new FlexPrintJob();


                if (printJob.start()) {
                    // Create a FormPrintView control
                    // as a child of the application.
                    var thePrintView:SCDPrintTemplate = new SCDPrintTemplate();
                    thePrintView.report=report;
                    thePrintView.scdno=scdno.text;

                    // Exclude the PrintAdvancedDataGrid control from layout.


                    addElement(thePrintView);

                    // Set the print view properties.
                    thePrintView.width=printJob.pageWidth;
                    thePrintView.height=printJob.pageHeight;
                    //thePrintView.prodTotal = prodTotal;

                    // Create a single-page image.
                    thePrintView.showPage("single");
                    // If the print image's DataGrid can hold all the
                    // data provider's rows, add the page to the print job.
                    if(!thePrintView.adg.validNextPage)
                    {
                        printJob.addObject(thePrintView);
                    }
                        // Otherwise, the job requires multiple pages.
                    else
                    {
                        // Create the first page and add it to the print job.
                        thePrintView.showPage("first");
                        printJob.addObject(thePrintView);
                        thePrintView.pageNumber++;
                        // Loop through the following code
                        // until all pages are queued.
                        while(true)
                        {
                            // Move the next page of data to the top of
                            // the PrintDataGrid.
                            thePrintView.adg.nextPage();
                            // Try creating a last page.
                            thePrintView.showPage("last");
                            // If the page holds the remaining data, or if
                            // the last page was completely filled by the last
                            // grid data, queue it for printing.
                            // Test if there is data for another
                            // PrintDataGrid page.
                            if(!thePrintView.adg.validNextPage)
                            {
                                // This is the last page;
                                // queue it and exit the print loop.
                                printJob.addObject(thePrintView);
                                break;
                            }
                            else
                                // This is not the last page. Queue a middle page.
                            {
                                thePrintView.showPage("middle");
                                printJob.addObject(thePrintView);
                                thePrintView.pageNumber++;
                            }
                        }

                    }
                    // All pages are queued; remove the FormPrintView
                    // control to free memory.
                    removeElement(thePrintView);
                }
                // Send the job to the printer.
                printJob.send();

            }

谢谢 :)

4

1 回答 1

0

试着打电话

thePrintView.validateNow(); 

打电话之前

thePrintView.showPage("single");

此外,我们已经围绕添加对此的内置支持做了大量工作。一探究竟。在http://blog.flexicious.com/post/Customizing-the-PrintExcel-Output.aspx

于 2011-11-11T18:44:00.267 回答