public ActionResult GenerateExcelReport(ReportExecutionBE reportexecution) { try { LoggingHelper.LogInformation("Retrieving parameters..."); if (reportexecution == null) { return(new EmptyResult()); } Byte[] results = ReportServer.DownloadExcel(HttpContext, reportexecution); var fileName = string.Format("{0}.xls", reportexecution.ReportName); if (results != null && results.Length > 0) { Session[fileName] = results; return(Json(new { success = true, fileName }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); } } catch (SqlException ex) { LoggingHelper.LogException("Unable to generate excel bytes from report service.", ex); throw; } catch (Exception ex) { LoggingHelper.LogException("Unable to generate excel bytes from report service.", ex); throw; } }
public static Byte[] DownloadExcel(System.Web.HttpContextBase httpContext, ReportExecutionBE reportexecution) { var rs = ReportWebServiceInstance(httpContext); var rsExec = new ReportExecutionService(); rsExec.Timeout = System.Threading.Timeout.Infinite; rsExec.Credentials = rs.Credentials; byte[] result = null; string format = "EXCEL"; string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; string extension; string encoding; string mimeType; ReportExecution.Warning[] warnings = null; string[] streamIDs = null; ExecutionInfo execInfo = new ExecutionInfo(); //var output = new HttpResponseMessage(); try { ReportExecution.ExecutionInfo ei = rsExec.LoadReport(reportexecution.ReportPath, null); List <ReportExecution.ParameterValue> parameters = new List <ReportExecution.ParameterValue>(); for (int i = 0; i < reportexecution.Parameters.Count; ++i) { for (int j = 0; j < reportexecution.Parameters[i].Value.Length; ++j) { ReportExecution.ParameterValue item = new ReportExecution.ParameterValue(); item.Name = reportexecution.Parameters[i].Name; item.Label = reportexecution.Parameters[i].Label; item.Value = reportexecution.Parameters[i].Value[j]; parameters.Add(item); } } ReportExecution.ParameterValue[] parametersExec = parameters.ToArray(); rsExec.SetExecutionParameters(parametersExec, "en-us"); result = rsExec.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); execInfo = rsExec.GetExecutionInfo(); } catch (SoapException ex) { //output = new HttpResponseMessage(HttpStatusCode.BadRequest); LoggingHelper.LogException("Unable to generate the excel file.", ex); } //return File(result, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", reportexecution.ReportName + "-" + execInfo.ExecutionDateTime + ".xlsx"); return(result); }
public ActionResult GetDependentParameters(ReportExecutionBE reportexecution) { try { string reportPath = reportexecution.ReportPath; List <ReportService.ParameterValue> values = new List <ReportService.ParameterValue>(); for (int i = 0; i < reportexecution.Parameters.Count; ++i) { ReportParameterBE valueList = reportexecution.Parameters[i]; if (valueList.Value != null) { for (int j = 0; j < valueList.Value.Length; ++j) { ReportService.ParameterValue value = new ReportService.ParameterValue(); value.Name = valueList.Name; value.Label = valueList.Label; value.Value = valueList.Value[j]; values.Add(value); } } } ItemParameter[] output = ReportServer.GetItemParameters(HttpContext, reportPath, null, true, values.ToArray(), null); return(Json(output, JsonRequestBehavior.AllowGet)); } catch (SqlException ex) { LoggingHelper.LogException("Unable to generate dependent parameters from report service.", ex); throw; } catch (Exception ex) { LoggingHelper.LogException("Unable to generate dependent parameters from report service.", ex); throw; } }