在flex 4.1中打印高级数据网格
我需要帮助打印我的高级数据网格。我尝试了不同的方法,但我得到的只是一张空白表格。
该表在那里,但其中没有标题或数据。这是我的代码:
<?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();
}
谢谢:)
I need help with printing my advanceddatagrid. I tried different ways but all I get is a blank table.
The table is there but there are no headers or data in it. Here's my code:
<?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>
here's my print function in the main code:
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();
}
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试调用
在调用之前
另外,我们已经做了很多工作来添加对此的内置支持。一探究竟。在 http://blog.flexicious.com/post/Customizing-the- PrintExcel-Output.aspx
Try calling
Before calling
Also, we've already done a lot of work around adding built in support for this. Check it out. at http://blog.flexicious.com/post/Customizing-the-PrintExcel-Output.aspx