使用ReportViewer Object打印Microsoft报告(.rdlc)

时间:2016-02-19 06:52:30

标签: c# rdlc reportviewer

  

我需要知道如何使用ReportViewer Object打印Microsoft报告(.rdlc)   没有Consol应用程序的WinFrom?   这种方式是否正确?

命名空间ReportProntTset {         公共课程{

        public static ReportViewer rp = new Microsoft.Reporting.WinForms.ReportViewer();

        static void Main(string[] args) {
        Start:
            Console.WriteLine("\nTo print picture one enter 0.\nFor second one enter any number.\n");
            int a = 0;
            string report = "";
            try {
                a = Convert.ToInt32(Console.ReadLine());
                if (a == 0) {
                    report = @"..\One.rdlc";
                }
                else {
                    report = @"..\Two.rdlc";
                }
                InitializeComponent(report);
                rp.Refresh();
                string ex = Print();
                if (ex != "") {
                    Console.WriteLine(ex);
                    goto Start;
                }
            }
            catch (Exception) {

                Console.WriteLine("Please Insert Right Charcter");
                goto Start;
            }
        }

        public static string Print() {
            string exa = "";
            try {
                rp.PrintDialog();
                rp.Clear();
                rp.LocalReport.ReleaseSandboxAppDomain();
            }
            catch (Exception ex) {

                exa = ex.Message;
            }
            return exa;
        }

        private static void InitializeComponent(string report) {
            Form fr = new Form();
            PrintDialog prDial = new System.Windows.Forms.PrintDialog();
            PrintDocument prDoc = new System.Drawing.Printing.PrintDocument();
            fr.SuspendLayout();

             //
             //pr
             //enter code here

            rp.LocalReport.ReportEmbeddedResource = report;
            rp.Location = new System.Drawing.Point(0, 0);
            rp.Name = "ViewReport";
            rp.Size = new System.Drawing.Size(0, 0);
            rp.TabIndex = 0;
            // 
            // prDial
            // `enter code here`
            prDial.UseEXDialog = true;
            // 
            // fr
            // 
            fr.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            fr.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            fr.ClientSize = new System.Drawing.Size(0, 0);
            fr.Controls.Add(rp);
            fr.Name = "ReportForm";
            fr.Text = "ImagePrint";
            fr.ResumeLayout(false);enter code here
        }
    }

}
  

有人可以帮我解决这个小问题。我相信添加或更改的内容很少:)

1 个答案:

答案 0 :(得分:0)

获取渲染的内容然后你可以做任何事情:

var content = reportViewer.LocalReport.Render("PDF")