刚开始用C#的时候就用到了水晶报表(当时用的是vs2003自带的),碰到了很多问题,后来慢慢的解决了,事隔2年,现在回想起来发现全忘记了,哎,所以决定自己再做个简单的小例子,复习下,顺便把操作过程简单的记录下,免得以后又忘记了
因为vs2003自带的crystalreport没有打印功能(WEB版的),所以现在用crystalreport10.0 DEVE版,安装顺序是先安装vs2003,再安装crystalreport10.0.
1、首先在项目中添加一个crystalreport,这样就会产生两个文件:CrystalReport1.rpt和CrystalReport1Service.asmx
2、在项目中添加两个数据集DataSet1.xsd和DataSet2.xsd,分别作为主报表和子报表的数据源
3、接下来就是报表设计了,其他细节就不说了,只是说下怎么把主报表和子报表关联起来,右键子报表选择“Change Subreport Links....",下面怎么做应该一看就知道了。
4、下面就是配置报表了:
一、构造数据源以及报表文件RPT文件位置
private void Button1_Click(object sender, System.EventArgs e)
{
获得报表数据源
}
二、数据源绑定:
try
{
string reportMethod = "ReportViewer"; //定义导出方式
if (System.Configuration.ConfigurationSettings.AppSettings["reportMethod"]!=null )
{
if(System.Configuration.ConfigurationSettings.AppSettings["reportMethod"].ToString()!="")
{
reportMethod = System.Configuration.ConfigurationSettings.AppSettings["reportMethod"].ToString(); //通过配置来获取导出方式
}
}
if(reportMethod != "ReportViewer" && reportMethod != "pdf" )
reportMethod = "ReportViewer";
string filtPath = this.MapPath("../") + Session["rptName"].ToString(); //获取RPT文件的绝对路径
oRpt.Load( this.MapPath("../") + (string)Session["rptName"]); //加载RPT文件
oRpt.SetDataSource(Session["rptsrc"]); //加载数据源

子报表
if(reportMethod == "ReportViewer" )
{
CrystalReportViewer1.ReportSource = oRpt;
}
else if (reportMethod == "pdf")
{
导出到PDF文件
}
}
catch(Exception ex)
{
throw ex;
}
这样就可以了,可能有点乱,不过没心思整理了
因为vs2003自带的crystalreport没有打印功能(WEB版的),所以现在用crystalreport10.0 DEVE版,安装顺序是先安装vs2003,再安装crystalreport10.0.
1、首先在项目中添加一个crystalreport,这样就会产生两个文件:CrystalReport1.rpt和CrystalReport1Service.asmx
2、在项目中添加两个数据集DataSet1.xsd和DataSet2.xsd,分别作为主报表和子报表的数据源
3、接下来就是报表设计了,其他细节就不说了,只是说下怎么把主报表和子报表关联起来,右键子报表选择“Change Subreport Links....",下面怎么做应该一看就知道了。
4、下面就是配置报表了:
一、构造数据源以及报表文件RPT文件位置
private void Button1_Click(object sender, System.EventArgs e)
{
获得报表数据源
}
try
{
string reportMethod = "ReportViewer"; //定义导出方式
if (System.Configuration.ConfigurationSettings.AppSettings["reportMethod"]!=null )
{
if(System.Configuration.ConfigurationSettings.AppSettings["reportMethod"].ToString()!="")
{
reportMethod = System.Configuration.ConfigurationSettings.AppSettings["reportMethod"].ToString(); //通过配置来获取导出方式
}
}
if(reportMethod != "ReportViewer" && reportMethod != "pdf" )
reportMethod = "ReportViewer";
string filtPath = this.MapPath("../") + Session["rptName"].ToString(); //获取RPT文件的绝对路径
oRpt.Load( this.MapPath("../") + (string)Session["rptName"]); //加载RPT文件
oRpt.SetDataSource(Session["rptsrc"]); //加载数据源
子报表
if(reportMethod == "ReportViewer" )
{
CrystalReportViewer1.ReportSource = oRpt;
}
else if (reportMethod == "pdf")
{
导出到PDF文件
}
}
catch(Exception ex)
{
throw ex;
}

浙公网安备 33010602011771号