如何直接打印rdlc报告而不在C#中显示PrintDialog()?

时间:2013-07-18 07:00:34

标签: c# printing rdlc

我有一个应用程序,我必须打印RDLC报告而不显示printDialog并使用应用程序中定义的默认指定打印机。下面是我的测试实现代码。

    Microsoft.Reporting.WinForms.ReportViewer reportViewerSales = new    Microsoft.Reporting.WinForms.ReportViewer();
    Microsoft.Reporting.WinForms.ReportDataSource reportDataSourceSales = new Microsoft.Reporting.WinForms.ReportDataSource();

    reportViewerSales.Reset();
        reportViewerSales.LocalReport.ReportPath = @"Sales.rdlc";

        reportDataSourceSales.Name = "SalesTableDataSet";

        int i = 1;
        foreach (Product item in ProductSalesList)
        {
            dataset.CurrentSales.AddCurrentSalesRow(i, item.Name, item.Quantity.ToString(), item.Price.ToString(), item.Price.ToString());
            i++;
        }
        reportDataSourceSales.Value = dataset.CurrentSales;
        reportViewerSales.LocalReport.DataSources.Add(reportDataSourceSales);
        dataset.EndInit();

        reportViewerSales.RefreshReport();
        reportViewerSales.RenderingComplete += new RenderingCompleteEventHandler(PrintSales);

这是我的渲染完成方法

public void PrintSales(object sender, RenderingCompleteEventArgs e)
    {
        try
        {

            reportViewerSales.PrintDialog();
            reportViewerSales.Clear();
            reportViewerSales.LocalReport.ReleaseSandboxAppDomain();
        }
        catch (Exception ex)
        {
        }
    }

2 个答案:

答案 0 :(得分:12)

我刚刚快速浏览了我创建的直接打印的类,我想我从这个演练中得到了一些想法: Printing a Local Report without Preview

答案 1 :(得分:-2)

public void PrintSales(object sender, RenderingCompleteEventArgs e)
{
    try
    {
        reportViewerSales.PageSetupDailog();
        reportViewerSales.PrintDialog();
        reportViewerSales.Clear();
        reportViewerSales.LocalReport.ReleaseSandboxAppDomain();
    }
    catch (Exception ex)
    {
    }
}