public ExportReportResult ExportStiReportStream(ReportInfo ri, String format, Stream output) { var rr = new ExportReportResult(); var targetFormat = (format ?? "pdf").ToLowerInvariant(); using (var stream = ri.GetStream(_host.ApplicationReader)) { var r = StiReportExtensions.CreateReport(stream, ri.Name); r.AddDataModel(ri.DataModel); if (ri.Variables != null) { r.AddVariables(ri.Variables); } if (targetFormat == "pdf") { r.Render(); r.ExportDocument(StiExportFormat.Pdf, output, StiReportExtensions.GetDefaultPdfSettings()); rr.ContentType = "application/pdf"; rr.Extension = "pdf"; } else if (format == "excel") { r.Render(); r.ExportDocument(StiExportFormat.Excel2007, output, StiReportExtensions.GetDefaultXlSettings()); rr.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; rr.Extension = "xlsx"; } else if (format == "word") { r.Render(); r.ExportDocument(StiExportFormat.Word2007, output, StiReportExtensions.GetDefaultWordSettings()); rr.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; rr.Extension = "docx"; } else if (format == "opentext") { r.Render(); r.ExportDocument(StiExportFormat.Odt, output, StiReportExtensions.GetDefaultOdtSettings()); rr.ContentType = "application/vnd.oasis.opendocument.text"; rr.Extension = "odt"; } else if (format == "opensheet") { r.Render(); r.ExportDocument(StiExportFormat.Ods, output, StiReportExtensions.GetDefaultOdsSettings()); rr.ContentType = "application/vnd.oasis.opendocument.spreadsheet"; rr.Extension = "ods"; } else { throw new NotImplementedException($"Format '{targetFormat}' is not supported in this version"); } } return(rr); }
// saveFileDialog: true -> download // saveFileDialog: false -> show public StiMvcActionResult ExportStiReport(ReportInfo ri, String format, bool saveFile = true) { var targetFormat = (format ?? "pdf").ToLowerInvariant(); using (var stream = _host.ApplicationReader.FileStreamFullPath(ri.ReportPath)) { var r = StiReportExtensions.CreateReport(stream, ri.Name); r.AddDataModel(ri.DataModel); if (ri.Variables != null) { r.AddVariables(ri.Variables); } if (targetFormat == "pdf") { return(StiMvcReportResponse.ResponseAsPdf(r, StiReportExtensions.GetPdfExportSettings(), saveFileDialog: saveFile)); } else if (format == "excel") { return(StiMvcReportResponse.ResponseAsExcel2007(r, StiReportExtensions.GetDefaultXlSettings(), saveFileDialog: saveFile)); } else if (format == "word") { return(StiMvcReportResponse.ResponseAsWord2007(r, StiReportExtensions.GetDefaultWordSettings(), saveFileDialog: saveFile)); } else if (format == "opentext") { return(StiMvcReportResponse.ResponseAsOdt(r, StiReportExtensions.GetDefaultOdtSettings(), saveFileDialog: saveFile)); } else if (format == "opensheet") { return(StiMvcReportResponse.ResponseAsOds(r, StiReportExtensions.GetDefaultOdsSettings(), saveFileDialog: saveFile)); } else { throw new NotImplementedException($"Format '{targetFormat}' is not supported in this version"); } } }