如何让XtraReport只打印数据而不打印格式内容

2025-03-24 18:36:26
推荐回答(1个)
回答1:

实现的功能:预览的时候数据和格式都可以看到,打印的时候只打印数据,这应该是套打功能最基本的要求。
基本思路:使用工具栏的printbarmanager控件,在printcontrol中显示XtraReports。创建两个XtraReport,一个是完整显示(xr),另一个只显示部分数据(xr_report)。打印的时候在printcontrol中显示xr_report,xr_report打印完毕时(PrintingSystem.EndPrint事件)换回xr。
关键点:设置xtrareport的格式后,还要执行CreateDocument()
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Preview;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Control;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
XtraReport1 xr = new XtraReport1();
XtraReport1 xr_other = new XtraReport1();
public Form1()
{
InitializeComponent();
xr_other.PrintingSystem.EndPrint += new EventHandler(PrintingSystem_EndPrint);
}
void PrintingSystem_EndPrint(object sender, EventArgs e)
{
printControl1.PrintingSystem = xr.PrintingSystem;
}
private void Form1_Load(object sender, EventArgs e)
{
printControl1.PrintingSystem = xr.PrintingSystem;
xr.CreateDocument();
xr_other.xrTable1.Borders = BorderSide.None;
xr_other.xrLabel1.Visible = false;
xr_other.CreateDocument();
}
private void printPreviewBarItem9_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
printControl1.PrintingSystem = xr_other.PrintingSystem;
}
private void printPreviewBarItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
printControl1.PrintingSystem = xr_other.PrintingSystem;
}
}
}