我正在导出报告,并且我注意到我为每个报告复制了大量代码。我想将其放在一个单独的类中的方法中,但是我不确定经过一些研究后如何进行实例化。我的代码如下:
ActiveReport rpt = new Reports.rptContractListing_Merchant();
rpt.Run();
try
{
rpt.Run(false);
}
catch (DataDynamics.ActiveReports.ReportException eRunReport)
{
// Failure running report, just report the error to the user:
Response.Clear();
Response.Write("<h1>Error running report:</h1>");
Response.Write(eRunReport.ToString());
return;
}
XlsExport xls = new XlsExport();
xls.MinColumnWidth = (float)0.5;
xls.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "inline; filename=ContractListing_Merchant.xls");
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
Response.BinaryWrite(m_stream.ToArray());
Response.End();
这是我不确定反射的部分:
ActiveReport rpt = new Reports.rptContractListing_Merchant();
另一个例子:
ActiveReport rpt = new Reports.rptContractDetails();
try
{
rpt.Run(false);
}
catch (DataDynamics.ActiveReports.ReportException eRunReport)
{
// Failure running report, just report the error to the user:
Response.Clear();
Response.Write("<h1>Error running report:</h1>");
Response.Write(eRunReport.ToString());
return;
}
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=ContractDetails.pdf");
PdfExport pdf = new PdfExport();
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
pdf.Export(rpt.Document, memStream);
Response.BinaryWrite(memStream.ToArray());
Response.End();
最佳答案
我认为Activator.CreateInstance<T>()
是您要生成的报告类型的方式