Liren's Blog
C0#1J0a1v0a1r0u0b1y0r1a1i1ls0f0l0e0x01
email:lirenzhao#gmail.com
首页
新闻
新随笔
联系
管理
订阅
随笔- 59 文章- 0 评论- 54
Flex 打印DataGrid内容 2.0
<?
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
>
绿色通道:
好文要顶
关注我
收藏该文
与我联系
posted @ 2007-01-24 20:14
Liren
阅读(2402)
评论(1)
编辑
收藏
发表评论
1686925
回复
引用
#1楼
2009-10-31 20:53
|
都是SB[未注册用户]
不看程序,
这个文件保存为 FormPrintView.mxml就行啦
注册用户登录后才能发表评论,请
登录
或
注册
,
返回博客园首页
。
首页
博问
闪存
新闻
园子
招聘
知识库
最新IT新闻
:
·
专访Jeffrey Richter:Windows 8是微软的重中之重
·
《福布斯》:谷歌进军硬件产品 难撼动苹果地位
·
美国空军拟最多购买1.8万台iPad 2
·
分析称专利之争让谷歌苹果两败俱伤
·
Android平台发现新型手机病毒Rootsmart
»
更多新闻...
最新知识库文章
:
·
高级编程语言的发展历程
·
如何学习一门新的编程语言?
·
学习不同编程语言的重要性
·
为什么我喜欢富于表达性的编程语言
·
计算机专业的女生为什么要学编程
»
更多知识库文章...
China-pub 2011秋季教材巡展
China-Pub 计算机绝版图书按需印刷服务
公告
这这里显示的是是公告,不不是母告
昵称:
Liren
园龄:
6年6个月
粉丝:
0
关注:
0
<
2007年1月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
更多链接
最新随笔
1. Spring MVC基于注解的Junit测试
2. Spring MVC 3中关于url-pattern设成"/"后,资源访问问题
3. ODI调用必须使用代理才能访问的web service
4. NotificationManager
5. 发送短信
6. 调用系统联系人列表
7. MorseCodeConverter 自用留存
8. Android 给自己的类加个事件
9. 用代码旋转屏幕
10. Android SQLiteHelper
随笔分类
(62)
.Cassandra(4)
(rss)
.Flex(18)
(rss)
.NET(7)
(rss)
.NET CF(13)
(rss)
.OTHERS(5)
(rss)
.Python(2)
(rss)
Android(7)
(rss)
Java(3)
(rss)
Ruby On Rails(3)
(rss)
推荐排行榜