有没有一种方法可以打印报告而不在报告查看器上预览它?

发布于 2024-08-22 12:27:34 字数 57 浏览 7 评论 0原文

我想直接打印报告 (RDL),而不进行预览。这项工作有解决办法吗?

I want to print a report (RDL) directly without previewing it. Is there a solution for this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛上残留的泪 2024-08-29 12:27:34

因此,我认为您想打印不带预览的报告,因此请查看

http:// /msdn.microsoft.com/en-us/library/ms252091.aspx

在那篇文章中,您会发现以下代码

使用系统;
  使用系统.IO;
  使用系统数据;
  使用系统文本;
  使用系统.绘图.成像;
  使用系统.绘图.打印;
  使用 System.Collections.Generic;
  使用 System.Windows.Forms;
  使用 Microsoft.Reporting.WinForms;
  public class Demo : IDisposable
  {
      private int m_currentPageIndex;
      private IList<Stream> m_streams;

  private DataTable LoadSalesData()
  {
    // Create a new DataSet and read sales data file 
    //    data.xml into the first DataTable.
    DataSet dataSet = new DataSet();
    dataSet.ReadXml(@"..\..\data.xml");
    return dataSet.Tables[0];
  }
    // Routine to provide to the report renderer, in order to
    //    save an image for each page of the report.
 private Stream CreateStream(string name,string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
  {
    Stream stream = new FileStream(@"..\..\" + name +
       "." + fileNameExtension, FileMode.Create);
    m_streams.Add(stream);
    return stream;
  }
    // Export the given report as an EMF (Enhanced Metafile) file.
  private void Export(LocalReport report)
  {
    string deviceInfo =
      "<DeviceInfo>" +
      "  <OutputFormat>EMF</OutputFormat>" +
      "  <PageWidth>8.5in</PageWidth>" +
      "  <PageHeight>11in</PageHeight>" +
      "  <MarginTop>0.25in</MarginTop>" +
      "  <MarginLeft>0.25in</MarginLeft>" +
      "  <MarginRight>0.25in</MarginRight>" +
      "  <MarginBottom>0.25in</MarginBottom>" +
      "</DeviceInfo>";
    Warning[] warnings;
    m_streams = new List<Stream>();
    report.Render("Image", deviceInfo, CreateStream,
       out warnings);
    foreach (Stream stream in m_streams)
        stream.Position = 0;
   }
     // Handler for PrintPageEvents
   private void PrintPage(object sender, PrintPageEventArgs ev)
   {
      Metafile pageImage = new
       Metafile(m_streams[m_currentPageIndex]);
      ev.Graphics.DrawImage(pageImage, ev.PageBounds);
      m_currentPageIndex++;
      ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
   }

   private void Print()
   {
    const string printerName =
       "Microsoft Office Document Image Writer";
    if (m_streams == null || m_streams.Count == 0)
        return;
    PrintDocument printDoc = new PrintDocument();
    printDoc.PrinterSettings.PrinterName = printerName;
    if (!printDoc.PrinterSettings.IsValid)
    {
        string msg = String.Format(
           "Can't find printer \"{0}\".", printerName);
        MessageBox.Show(msg, "Print Error");
        return;
    }
    printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
    printDoc.Print();
   }
  // Create a local report for Report.rdlc, load the data,
  //    export the report to an .emf file, and print it.
  private void Run()
  {
    LocalReport report = new LocalReport();
    report.ReportPath = @"..\..\Report.rdlc";
    report.DataSources.Add(
       new ReportDataSource("Sales", LoadSalesData()));
    Export(report);
    m_currentPageIndex = 0;
    Print();
 } 

  public void Dispose()
  {
    if (m_streams != null)
    {
        foreach (Stream stream in m_streams)
            stream.Close();
        m_streams = null;
    }
  }

  public static void Main(string[] args)
  {
    using (Demo demo = new Demo())
    {
        demo.Run();
    }
  }
 }

So I think you want to print a Report without Preview so check this out

http://msdn.microsoft.com/en-us/library/ms252091.aspx

in that article youfind following code

using System;
  using System.IO;
  using System.Data;
  using System.Text;
  using System.Drawing.Imaging;
  using System.Drawing.Printing;
  using System.Collections.Generic;
  using System.Windows.Forms;
  using Microsoft.Reporting.WinForms;
  public class Demo : IDisposable
  {
      private int m_currentPageIndex;
      private IList<Stream> m_streams;

  private DataTable LoadSalesData()
  {
    // Create a new DataSet and read sales data file 
    //    data.xml into the first DataTable.
    DataSet dataSet = new DataSet();
    dataSet.ReadXml(@"..\..\data.xml");
    return dataSet.Tables[0];
  }
    // Routine to provide to the report renderer, in order to
    //    save an image for each page of the report.
 private Stream CreateStream(string name,string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
  {
    Stream stream = new FileStream(@"..\..\" + name +
       "." + fileNameExtension, FileMode.Create);
    m_streams.Add(stream);
    return stream;
  }
    // Export the given report as an EMF (Enhanced Metafile) file.
  private void Export(LocalReport report)
  {
    string deviceInfo =
      "<DeviceInfo>" +
      "  <OutputFormat>EMF</OutputFormat>" +
      "  <PageWidth>8.5in</PageWidth>" +
      "  <PageHeight>11in</PageHeight>" +
      "  <MarginTop>0.25in</MarginTop>" +
      "  <MarginLeft>0.25in</MarginLeft>" +
      "  <MarginRight>0.25in</MarginRight>" +
      "  <MarginBottom>0.25in</MarginBottom>" +
      "</DeviceInfo>";
    Warning[] warnings;
    m_streams = new List<Stream>();
    report.Render("Image", deviceInfo, CreateStream,
       out warnings);
    foreach (Stream stream in m_streams)
        stream.Position = 0;
   }
     // Handler for PrintPageEvents
   private void PrintPage(object sender, PrintPageEventArgs ev)
   {
      Metafile pageImage = new
       Metafile(m_streams[m_currentPageIndex]);
      ev.Graphics.DrawImage(pageImage, ev.PageBounds);
      m_currentPageIndex++;
      ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
   }

   private void Print()
   {
    const string printerName =
       "Microsoft Office Document Image Writer";
    if (m_streams == null || m_streams.Count == 0)
        return;
    PrintDocument printDoc = new PrintDocument();
    printDoc.PrinterSettings.PrinterName = printerName;
    if (!printDoc.PrinterSettings.IsValid)
    {
        string msg = String.Format(
           "Can't find printer \"{0}\".", printerName);
        MessageBox.Show(msg, "Print Error");
        return;
    }
    printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
    printDoc.Print();
   }
  // Create a local report for Report.rdlc, load the data,
  //    export the report to an .emf file, and print it.
  private void Run()
  {
    LocalReport report = new LocalReport();
    report.ReportPath = @"..\..\Report.rdlc";
    report.DataSources.Add(
       new ReportDataSource("Sales", LoadSalesData()));
    Export(report);
    m_currentPageIndex = 0;
    Print();
 } 

  public void Dispose()
  {
    if (m_streams != null)
    {
        foreach (Stream stream in m_streams)
            stream.Close();
        m_streams = null;
    }
  }

  public static void Main(string[] args)
  {
    using (Demo demo = new Demo())
    {
        demo.Run();
    }
  }
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文