'Need help in render rdlc in multiple worksheets
protected void BtnSubmitGSFC_Click(object sender, EventArgs e) { if (ddlGFSCCargo.SelectedValue == "00") { ClientScript.RegisterStartupScript(this.GetType(), "SAVE", "alert('Please Select Cargo');"); return; } string url; int CargoGSFC = int.Parse(ddlGFSCCargo.SelectedValue); System.Data.DataSet DS = null; System.Data.DataSet DS1 = null; SqlDataAdapter Cont = new SqlDataAdapter(ConfigurationManager.AppSettings["VslID"], ConfigurationManager.ConnectionStrings["Connectionstring"].ConnectionString); System.Data.DataTable dt0; dt0 = new System.Data.DataTable(); Cont.Fill(dt0); Microsoft.Office.Interop.Excel.Application app = null; app = new Microsoft.Office.Interop.Excel.Application(); app.Workbooks.Add(""); int TotalRow = dt0.Rows.Count; string[] res = new string[TotalRow];
for (int i = 0; i < TotalRow; i++)
{
try
{
ReportViewer viewer = new ReportViewer();
LocalReport report = new LocalReport();
SQLHelper objSQL = new SQLHelper();
SqlParameter[] SqlParam1 = new SqlParameter[2];
SqlParameter[] SqlParam2 = new SqlParameter[1];
SqlParam1[0] = new SqlParameter("@VesselID", dt0.Rows[i][0].ToString());
SqlParam1[1] = new SqlParameter("@Cargo", CargoGSFC);
DS = objSQL.ExecuteDataSet("SP_GFSC_Daily_Rpt", SqlParam1);
viewer.LocalReport.ReportPath = Server.MapPath("~/RDLC/GFSC_Rpt.rdlc");
SqlParam2[0] = new SqlParameter("@VesselID", dt0.Rows[i][0].ToString());
DS1 = objSQL.ExecuteDataSet("Sp_GSFC_Reg_Select", SqlParam2);
viewer.LocalReport.ReportPath = Server.MapPath("~/RDLC/GFSC_Rpt.rdlc");
ReportDataSource reportDSDetail1 = new ReportDataSource("GFSC", DS.Tables[0]);
viewer.LocalReport.DataSources.Add(reportDSDetail1);
ReportDataSource reportDSDetail2 = new ReportDataSource("Rpt_Gspc", DS1.Tables[0]); viewer.LocalReport.DataSources.Add(reportDSDetail2);
FileStream fs = null;
Warning[] warnings;``
string[] streamIds;
string contentType;
string encoding;
string extension;
//create file stream in create mode
fs = new FileStream(DS.Tables[0].Rows[0]["VesselID"] + "_GSFC.xls", FileMode.Create);
byte[] bytes = viewer.LocalReport.Render("EXCEL", null, out contentType, out encoding, out extension, out streamIds, out warnings);
//create Excel file
fs.Write(bytes, 0, bytes.Length);
fs.Close();
fs = null;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
