简体   繁体   English

使用ReportViewer对象打印Microsoft report(.rdlc)

[英]Print Microsoft report(.rdlc) with ReportViewer Object

I need to know how to print Microsoft report(.rdlc) with ReportViewer Object without WinFrom from Consol Application? 我需要知道如何从Consol Application中使用不带WinFrom的ReportViewer Object打印Microsoft report(.rdlc)吗? Is this way correct? 这样正确吗?

namespace ReportProntTset { public class Program { 命名空间ReportProntTset {公共类Program {

        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
        }
    }

}

Can U someone help me with that little issue. 有人可以帮我解决这个小问题吗? I believe there is few thing to add or change :) 我相信没有什么要添加或更改的了:)

获取渲染的内容,然后您可以执行任何操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM