gpt4 book ai didi

angular - 如何在 Angular 2 应用程序中显示 SSRS 报告

转载 作者:行者123 更新时间:2023-12-02 08:15:55 27 4
gpt4 key购买 nike

我一直在互联网上寻找一些关于如何在 Angular 2 中显示报告的线索。到目前为止,我还没有找到任何我可以依赖的东西。如果有人能在这里帮助我,我将非常感激。

最佳答案

我不能确定,但​​现在我的答案是我们无法在 Angular 2 中显示 SSRS 报告。但是您可以使用 webapi 将 SSRS 报告转换并呈现​​为 PDF,并使用 Iframe、popwindow 和 ng2-pdf-viewer 在 Angular 应用程序中显示它。

我更喜欢 popwindow 和 ng2-pdf-viewer bcz Iframe 不能在 ios 和 mac 浏览器(如 safari 等)上工作。

现在这是我将 ssrs 报告转换为 pdf 的示例 api

    [HttpGet]    [Route("ShowReport/PDF")]    [AllowAnonymous]    [ResponseType(typeof(ServerResponse))]    public HttpResponseMessage ShowReport(string ReponseType)    {        using (blBaseCore bl = new blBaseCore(AppConfig.DefaultConnectionString, 1, 1))        {            List prms = new List();            prms.Add(new ReportParameter("PARAM1_NAME", "PARAM1_VALUE"));            prms.Add(new ReportParameter("PARAM2_NAME", "PARAM2_VALUE"));            return this.GenrateReport("SSRS_REPORT_NAME", "PDF_FILE_NAME", ReponseType, prms);        }    }    ///     /// Genrates the report.    ///     /// Name of the report.    /// Name of the export file.    /// Type of the export file.    /// The PRMS.    /// HttpResponseMessage.    public HttpResponseMessage GenrateReport(string reportName, string ExportFileName, string ExportFileType, List prms)    {        var result = new HttpResponseMessage(HttpStatusCode.OK);        try        {            if (!(new string[] { "pdf", "excel" }).Contains(ExportFileType.ToLower()))                throw new Exception("Invalid file format");            string ServerPath = AppConfig.AppSettings("Systemic.ReportServer.BaseUrl");            string ReportFolder = AppConfig.AppSettings("Systemic.ReportServer.FolderPath");            byte[] bytes = null;            using (var reportViewer = new ReportViewer())            {                //reportViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials("Prabakaran", "LooserNo1", "SERVER");                reportViewer.ShowPrintButton = false;                reportViewer.ShowZoomControl = false;                reportViewer.PageCountMode = PageCountMode.Actual;                reportViewer.ProcessingMode = ProcessingMode.Remote;                reportViewer.ServerReport.ReportServerUrl = new System.Uri(ServerPath);                reportViewer.ServerReport.ReportPath = "/" + ReportFolder + "/" + reportName;                if (prms.Count > 0)                {                    reportViewer.ServerReport.SetParameters(prms);                }                reportViewer.ServerReport.Refresh();                if (reportViewer.ServerReport.IsReadyForRendering && ExportFileType.ToLower() == "pdf")                {                    bytes = reportViewer.ServerReport.Render("PDF", DeviceInfo(reportViewer));                    //bytes = reportViewer.ServerReport.Render("PDF");                    if (bytes != null)                    {                        Stream stream = new MemoryStream(bytes);                        result.Content = new StreamContent(stream);                        result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");                    }                }                else if (reportViewer.ServerReport.IsReadyForRendering && ExportFileType.ToLower() == "excel")                {                    bytes = reportViewer.ServerReport.Render("excel");                    if (bytes != null)                    {                        Stream stream = new MemoryStream(bytes);                        result.Content = new StreamContent(stream);                        result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");                        result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");                        result.Content.Headers.ContentDisposition.FileName = $"{ExportFileName}.xls";                    }                }            }            return result;        }        catch (Exception ex)        {            var res = Request.CreateResponse(HttpStatusCode.OK, ServerResponse.Error(ex, 501));            res.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");            AppLog.Write(ex.Message, LogName.Report, LogType.Error);            return res;        }    }    protected string DeviceInfo(ReportViewer rv)    {        ReportPageSettings rps = rv.ServerReport.GetDefaultPageSettings();        //PageSettings ps = rv.GetPageSettings();        PaperSize paperSize = rps.PaperSize;        Margins margins = rps.Margins;        // The device info string defines the page range to print as well as the size of the page.        // A start and end page of 0 means generate all pages.        if (!rps.IsLandscape)        {            return string.Format(                CultureInfo.InvariantCulture,                "emf00{0}{1}{2}{3}{4}{5}",                ToInches(margins.Top),                ToInches(margins.Left),                ToInches(margins.Right),                ToInches(margins.Bottom),                ToInches(paperSize.Height),                ToInches(paperSize.Width));        }        else        {            return string.Format(                CultureInfo.InvariantCulture,                "emf00{0}{1}{2}{3}{4}{5}",                ToInches(margins.Top),                ToInches(margins.Left),                ToInches(margins.Right),                ToInches(margins.Bottom),                ToInches(paperSize.Width),                ToInches(paperSize.Height));        }    }    protected string ToInches(int hundrethsOfInch)    {        double inches = hundrethsOfInch / 100.0;        return inches.ToString(CultureInfo.InvariantCulture) + "in";    }

关于angular - 如何在 Angular 2 应用程序中显示 SSRS 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42728456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com