本文说明怎样使用MyReport来实现Flex DataGrid组件的自己主动化打印预览和打印功能。

实现代码

<?

xmlversion="1.0" encoding="utf-8"?>

<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"

width="" horizontalAlign=""

paddingLeft="" paddingRight="" paddingTop="" creationComplete="Init()">

<mx:Script>

<![CDATA[

import mx.collections.ArrayCollection;

import myreport.ReportEngine;

import myreport.ReportViewer;

import myreport.data.report.CaptionCellSetting;

import myreport.data.report.CaptionRowSetting;

import myreport.data.report.ReportSettings;

import myreport.data.report.TableCellSetting;

import myreport.data.report.TableColumnSetting;

import myreport.data.report.TableRowSetting;

private function Init():void

{

//初始化时设置DataGrid的数据源

_Grid.dataProvider = GetTableData();

}

private function GetTableData():ArrayCollection

{

var list:ArrayCollection = new ArrayCollection();

for (var i:int =0; i < 25; i++)

{

list.addItem({ID: i, 名称: "商品信息XXX 规格XXX 型号XXX", 数量: i+1, 金额: (i+1)*10, 日期:newDate()});

}

return list;

}

private function PreviewReport():void

{

//预览

var style:ReportSettings= DataGridToMyReport(_Grid, "演示样例:DataGridToMyReport");

myreport.ReportViewer.Instance.Show(new XML(style.ToXML()), style.TableData, style.ParameterData);

}

private function PrintReport():void

{

//直接打印

var style:ReportSettings= DataGridToMyReport(_Grid, "演示样例:DataGridToMyReport");

myreport.ReportEngine.PrintAsync(new XML(style.ToXML()), style.TableData, style.ParameterData);

}

/**

*

* 封装的转换方法。实现DataGid转成报表样式

*

* @param grid: 表格控件(传入前确保表格控件已经设置数据源)

* @param title:报表标题

*/

private function DataGridToMyReport(grid:DataGrid,title:String):ReportSettings

{

var style:ReportSettings = new ReportSettings();

//数据源

style.TableData = grid.dataProvideras ArrayCollection;

var params:Dictionary = newDictionary();

params.Title = title;

style.ParameterData = params;

//报表样式

style.TableHeaderRepeat = true;//表格头反复

style.TableFooterRepeat = true;//表格尾反复

style.AutoWidth = true;//报表宽度自己主动递增

style.PageByColumn = true;//分栏打印

style.SetUnit("px");

//标题

var captionRow:CaptionRowSetting = new CaptionRowSetting();

var caption:CaptionCellSetting = new CaptionCellSetting();

caption.Width = style.ClientWidth;

caption.Style.FontBold = true;

caption.Style.FontSize = 16;

caption.Style.TextAlign = "center";

caption.Value = "=@Title";

captionRow.CaptionCellSettings.push(caption);

style.PageHeaderSettings.push(captionRow);

//表格

var headerRow:TableRowSetting = new TableRowSetting();

var contentRow:TableRowSetting = new TableRowSetting();

var gridColumns:Array = grid.columns;

for each(var gridCol:DataGridColumnin gridColumns)

{

if(!gridCol.visible)

continue;

//加入列

var column:TableColumnSetting = new TableColumnSetting();

column.Width = gridCol.width;

style.TableColumnSettings.push(column);

//加入表格头单元格

var headerCell:TableCellSetting = new TableCellSetting();

headerCell.Style.FontBold = true;

headerCell.Style.TextAlign = "center";

headerCell.Value = gridCol.headerText;

headerRow.TableCellSettings.push(headerCell);

//加入表格主体单元格

var contentCell:TableCellSetting = new TableCellSetting();

contentCell.Value = "=#" + gridCol.dataField;

contentRow.TableCellSettings.push(contentCell);

}

style.TableHeaderSettings.push(headerRow);

style.TableDetailSettings.push(contentRow);

return style;

}

]]>

</mx:Script>

<mx:Label text="演示怎样用程序动态生成报表样式,实现DataGrid to MyReport。

" width="100%" textAlign="center"/>

<mx:Button label="打印预览"click="PreviewReport()"/>

<mx:Button label="直接打印"click="PrintReport()"/>

"height="100%" horizontalScrollPolicy="on">

<mx:columns>

"/>

"/>

"/>

"/>

"/>

</mx:columns>

</mx:DataGrid>

</mx:VBox>

效果图

MyReport介绍

MyReport产品站点

相关文章

MyReport专栏

备注

*技术交流与合作:QQ: 791663094。Email:kong.yee@foxmail.com

MyReport:DataGrid的打印和打印预览的更多相关文章

  1. Lodop中特殊符号¥打印设计和预览不同

    Lodop中¥符号样式改变问题 Lodop中对超文本样式的解析,虽然说是按照调用的本机ie引擎,但是调用的ie版本可能不同,导致在ie下是一种样式,预览又是另一种样式.可能是有些样式没有具体设置,走的 ...

  2. JS Web打印,实现预览新样式

    问题描述:     JS实现Web打印,要求打印前一种样式,打印预览时新样式 问题解决:         (1)设置打印时的css样式,设置打印前的css样式 注:         以上为print. ...

  3. asp.net调用Lodop实现页面打印或局部打印,可进行打印设置或预览

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebPrint.aspx.cs ...

  4. css去掉使用bootstrap框架后打印网页时预览效果下的超链接

    在我们写网页的时候,超链接是链接各个页面的桥梁,也是搜索引擎爬虫(spider)收录网站页面的关键,因此,在每个网页中会有许多的超链. 今天,一个同行妹妹在使用了bootstrap框架来搭建自己的网站 ...

  5. java原装代码完成pdf在线预览和pdf打印及下载

    这是我在工作中,遇到这样需求,完成需求后,总结的成果,就当做是工作笔记,以免日后忘记,当然,能帮助到别人是最好的啦! 下面进入正题: 前提准备: 1. 项目中至少需要引入的jar包,注意版本: a)  ...

  6. Lodop打印设计矩形重合预览线条变粗

    LODOP中的打印设计是辅助进行开发的,实际打印效果应以预览为准,很多效果都是在设计界面显示不出来,或设计和预览界面有差异.例如add_print_text文本的字间距.行间距,旋转,还有允许标点溢出 ...

  7. Winform中使用FastReport实现自定义PDF打印预览

    场景 Winform中使用FastReport实现简单的自定义PDF导出: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1009 ...

  8. easyui多图片上传+预览切换+支持IE8

    引入css和js: <link href="${pageContext.request.contextPath}/plugin/dialog/dialog.css" rel= ...

  9. C# 使用PrintDocument 绘制表格 完成 打印预览

    C# 使用PrintDocument 绘制表格 完成 打印预览 DataTable   经过不断的Google与baidu,最终整理出来的打印类 主要是根据两个参考的类组合而成,稍微修改了一下,参考代 ...

随机推荐

  1. 【LeetCode】228 - Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  2. C字符串和C++中string的区别 &&&&C++中int型与string型互相转换

    在C++中则把字符串封装成了一种数据类型string,可以直接声明变量并进行赋值等字符串操作.以下是C字符串和C++中string的区别:   C字符串 string对象(C++) 所需的头文件名称 ...

  3. 用js完成blog项目

    //前台调用 var $ = function (args) { return new Base(args); } //基础库 function Base(args) { //创建一个数组,来保存获取 ...

  4. Mac下用命令行直接批量转换文本编码到UTF8

    由于近期在Mac下写Android程序,下载的一些Demo由于编码问题源码里的汉字出现乱码,文件比较多,所以想批量解决下文件的编码问题. Mac下有以下两种方式可以解决: A. 文件名的编码:Mac的 ...

  5. CentOS下挂在NTFS分区

    本文参考自http://www.cnblogs.com/gbyukg/archive/2011/11/02/2232343.html centos下想访问NTFS分区,现在普遍的方法是利用ntfs-3 ...

  6. cannot restore segment prot after reloc: Permission denied

    编辑/etc/selinux/config,找到这段:# This file controls the state of SELinux on the system. # SELINUX= can t ...

  7. Cocos2d-JS v3.0 alpha

    Cocos2d-JS是整合了Cocos2d-html5 v3.0 alpha和Cocos2d-x JSBinding的新JS引擎仓库.整合之后的核心优势在于Html5和JSB的开发流程及API现在变得 ...

  8. USB2.0规范

    USB是一种支持热插拔的高速串行传输总线,它使用差分信号来传输数据,最高速度可达480Mb/S. USB支持“总线供电”和“自供电”两种供电模式.在总线供电模式下,设备最多可以获得500mA的电流.U ...

  9. Leetcode237:Delete Node in a Linked List

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  10. whereis 命令

    whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息. 和find相比,whereis查找的速度非 ...