通用Crystal报表是否可以在运行时动态地即时报告? [英] Can a generic Crystal report be dynamically instantied at runtime?
问题描述
以下代码将实例化一个特定的Crystal报表(TestRpt.rpt):
public static void CreatePDF()
{
DataSet ds = TestDAL.GetCrystalDS();
TestRpt rpt = new TestRpt();
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t," TestRpt.pdf");
}
但是,我想概括一下这样的报告名字可以通过
in ...像这样的东西(虽然我意识到这不会起作用,但是你得到了这个想法):
public static void CreatePDF(string reportName)
{
DataSet ds = TestDAL.GetCrystalDS();
ReportName rpt = new ReportName(); <<<如何在运行时执行这样的操作?
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t, ReportName +
" .pdf");
}
The following code will instantiate a specific Crystal report (TestRpt.rpt):
public static void CreatePDF()
{
DataSet ds = TestDAL.GetCrystalDS();
TestRpt rpt = new TestRpt();
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t, "TestRpt.pdf");
}
However, I would like to generalize this so the report name can be passed
in... something like this (although I realize this won''t work, but you get
the idea):
public static void CreatePDF(string reportName)
{
DataSet ds = TestDAL.GetCrystalDS();
ReportName rpt = new ReportName(); <<< how would I do something like
this at runtime?
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t, ReportName +
".pdf");
}
推荐答案
我不知道不明白你的TestRpt课程是什么......?它是否继承了
ReportDocument?你能发贴一些代码吗?
I don''t understand what your TestRpt class is...? Does it inherit from
ReportDocument? Could you post some code?
它继承自Crystal ReportClass。
" Bruce Wood" <峰; br ******* @ canada.com>在消息中写道
news:11 ********************** @ e56g2000cwe.googlegr oups.com ...
It inherits from the Crystal ReportClass.
"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
我不明白你的TestRpt课程是什么......?它是否继承自
ReportDocument?你能发一些代码吗?
I don''t understand what your TestRpt class is...? Does it inherit from
ReportDocument? Could you post some code?
啊。这是由Visual Studio生成的.cs文件,当它创建了rpt的
时,对吗?
我从来没有用过那个类任何东西。我认为这是垃圾。我在运行时将
实例化我的报告:
ReportDocument myReport = new ReportDocument();
myReport.Load(" ; MyReport.rpt");
myReport.SetDataSource(myDataSet);
Ahh. That''s in the .cs file generated by Visual Studio when it creates
the rpt, right?
I''ve never used that class for anything. I consider it junk. I
instantiate my reports at runtime like this:
ReportDocument myReport = new ReportDocument();
myReport.Load("MyReport.rpt");
myReport.SetDataSource(myDataSet);
这篇关于通用Crystal报表是否可以在运行时动态地即时报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!