bind multiple crystal report to one excel sheet
This for the ASPX page. There should be a CrystalReportViewer to view the report
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
DisplayGroupTree="False" HasCrystalLogo="False" HasSearchButton="False" HasToggleGroupTreeButton="False"
HasViewList="False" />
//Then below code for the .cs class file
// namespaces required
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
DisplayGroupTree="False" HasCrystalLogo="False" HasSearchButton="False" HasToggleGroupTreeButton="False"
HasViewList="False" />
//Then below code for the .cs class file
// namespaces required
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxGridView;
using System.Data;
using DevExpress.Web.ASPxClasses;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;
protected void ASPxButton1_Click(object sender, EventArgs e)
{
CrystalDecisions.CrystalReports.Engine.ReportDocument rptDocMain = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
//here added a main crystal rep
rptDocMain.Load(Server.MapPath("~/Web/Reports/main.rpt"));
DataTable dt = new DataTable();
dt= null;
dt= getDataToTables():
CrystalDecisions.CrystalReports.Engine.ReportDocument rptSub = rptDocMain.OpenSubreport("subReprt.rpt");
//then added a sub crystal report
rptSub.SetDataSource(dt);
rptDocMain.ReportDefinition.Sections[3].SectionFormat.EnableSuppress = false;
// like wise if you want to add more sub reports you can itterate aboue few set of code lines.
// Now I am going to bind the data to a Excel sheet.
string repName="";
MemoryStream oStream;
oStream = (MemoryStream)
rptDocMain.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
Response.Clear();
Response.Buffer = true;
rptDocMain.ExportToHttpResponse(ExportFormatType.Excel, Response, false, repName);
Response.BinaryWrite(oStream.ToArray());
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxGridView;
using System.Data;
using DevExpress.Web.ASPxClasses;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;
protected void ASPxButton1_Click(object sender, EventArgs e)
{
CrystalDecisions.CrystalReports.Engine.ReportDocument rptDocMain = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
//here added a main crystal rep
rptDocMain.Load(Server.MapPath("~/Web/Reports/main.rpt"));
DataTable dt = new DataTable();
dt= null;
dt= getDataToTables():
CrystalDecisions.CrystalReports.Engine.ReportDocument rptSub = rptDocMain.OpenSubreport("subReprt.rpt");
//then added a sub crystal report
rptSub.SetDataSource(dt);
rptDocMain.ReportDefinition.Sections[3].SectionFormat.EnableSuppress = false;
// like wise if you want to add more sub reports you can itterate aboue few set of code lines.
// Now I am going to bind the data to a Excel sheet.
string repName="";
MemoryStream oStream;
oStream = (MemoryStream)
rptDocMain.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
Response.Clear();
Response.Buffer = true;
rptDocMain.ExportToHttpResponse(ExportFormatType.Excel, Response, false, repName);
Response.BinaryWrite(oStream.ToArray());
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
Comments
Post a Comment