【发布时间】:2016-02-19 19:17:08
【问题描述】:
我需要知道如何使用 ReportViewer 对象打印 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
}
}
}
有人能帮我解决这个小问题吗?我相信没有什么可以添加或更改的:)
【问题讨论】:
-
最好将此报告导出为 pdf/image 等,并打印此 pdf/image
-
不使用 Windows 窗体,您会将 ReportViewer 放在哪里?
-
@Hemal 我不知道。是否有必要使用 WinForm?提前致谢
-
如果你想使用
ReportViewer,正如你在你的问题中所说,那么Form是必须的。 -
您不需要 ReportViewer 来打印报告或将其导出为 PDF、Excel 或 Word 格式。见这里:msdn.microsoft.com/en-us/library/ms252091.aspx
标签: c# rdlc reportviewer