Devexpress WPF Reporting 系列教程——【1.1】打印一个报表

目录


  1. 打印
    1. 打印一个报表
    2. 管理打印进度
    3. 配置打印数量
    4. 依据范围打印
    5. 配置纸张源、分辨率
    6. 共享打印机设置
    7. 从远端服务打印
  2. 文档预览
    1. 快速开始
    2. GUI
    3. API和自定义
  3. 报表设计器
    1. 快速开始
    2. GUI
    3. API和自定义
  4. 应用安全
    1. 安全加载
    2. 数据安全访问
  5. UI显示
    1. 修改应用主题
    2. 修改图标,位图、适量图
  6. 本地化显示
    1. 本地化打印预览
    2. 本地化报表设计器

本系列教程基于DevExpress 官方帮助文档。帮助文档下载地址


本文是针对WPF的文档,当然你也可以用于WInform。

基本方法

你可以使用PrintHelper类打印Report。

PrintHelpe.PrintDirect方法使用默认打印设置将报表发送到打印机。此方法提供重载,允许您使用系统的默认打印机或特定打印,显示的UI如下

  •  

打印一个简单报表示例

using DevExpress.Xpf.Printing;
// ...

private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e) {
    XtraReport1 report = new XtraReport1();

    // Invoke the Print dialog.
    PrintHelper.Print(report);

    // Send the report to the default printer.
    PrintHelper.PrintDirect(report);

    // Send the report to the specified printer.
    PrintHelper.PrintDirect(report, "myPrinter");
}

 XtraReport1 是一个设计的自定义报表。你可以用VS 设计,也可以报表设计器设计。

调用这几个方法会自动创建一个文档(文档不存在的情况下),自动调用的方法是 XtraReport.CreateDocument

如果你要将多个报表一起打印(对于打印机来说就是一个任务),你需要将这个报表合并到一个文档中。具体操作请参考合并报表页面

打印大型报表

使用CachedReportSource组件打印包含大量数据的报表。此组件允许您在文档生成期间将页面存储在文件系统或数据库中,从而避免内存消耗过度。

示例代码如下

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
//...
    var storage = new MemoryDocumentStorage();
    var report = new XtraReport1();
    var cachedReportSource = new CachedReportSource(report, storage); 

代码中使用的MemoryDocumentStorage可以将文档紧凑地存储在内存中。当然你也可以使用FileDocumentStorage、DbDocumentStorage或实现自定义存储。

示例代码如下

using DevExpress.Xpf.Printing;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...

private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e) {
    var storage = new MemoryDocumentStorage();
    var report = new XtraReport1();
    var cachedReportSource = new CachedReportSource(report, storage); 

    // Invoke the Print dialog.
    PrintHelper.Print(cachedReportSource);

    // Send the report to the default printer.
    PrintHelper.PrintDirect(cachedReportSource);

    // Send the report to the specified printer.
    PrintHelper.PrintDirect(cachedReportSource, "myPrinter");
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值