【问题标题】:How to use stimulsoft in .NET6?如何在 .NET6 中使用 stimulsoft?
【发布时间】:2022-11-12 13:08:36
【问题描述】:

我想在一个项目中使用 stimulsoftASP.NET MVC .Net6. StimulSoft 版本是 2022.1.1,我安装了 NuGet

Stimulsoft.Reports.Web.NetCore

在我的项目中。

控制器:

    ...
    public IActionResult PrintPage()
    {
        return View();
    }

    public IActionResult GetReport()
    {
        StiReport report = new StiReport();
        report.Load(StiNetCoreHelper.MapPath(this, "wwwroot/Reports/sample1.mrt"));
        var list = _unitOfWork.RefereeTypeRepos.GetAll(); //Get information for print.
        report.RegData("DT", list);
        return StiNetCoreViewer.GetReportResult(this, report);
    }

    public IActionResult ViewerEvent()
    {
        return StiNetCoreViewer.ViewerEventResult(this);
    }

打印页面.cshtml:

    @using Stimulsoft.Report.Mvc
    @using Stimulsoft.Report.Web
    @Html.StiNetCoreViewer(new StiNetCoreViewerOptions()
    {
        Actions =
        {
            GetReport = "GetReport",
            ViewerEvent = "ViewerEvent"
        }
    })

当页面加载时,我得到了这个错误

我不知道我应该做什么,哪个版本或 NuGet 适合 .Net6? 我感谢有人回答。

【问题讨论】:

  • 我的问题有什么问题,有人投票反对我?
  • 我搜索了很多并尝试了许多不同的代码。而不是'report.load'我使用'report.loadducument'错误消失了,但只显示一个空页面,使用Stimulsoft的试用版。

标签: c# asp.net-mvc .net-6.0 stimulsoft


【解决方案1】:

这个对我有用:

public IActionResult GetReport()
    {
        var person = new { Name = "samplename", Family = "samplefamily" };
        StiReport report = new StiReport();

        var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
        report.Load(path + "\Reports\Ticket.mrt");

        var service = new Stimulsoft.Report.Export.StiPdfExportService();

        report.RegData("PersonDetail", person);
        
        report.Render(false);

        StiPdfExportSettings st = new StiPdfExportSettings();
        st.ImageQuality = 1f;
        st.EmbeddedFonts = true;
        st.ImageResolution = 300;
        st.ImageFormat = StiImageFormat.Color;
        st.AllowEditable = StiPdfAllowEditable.No;

        var stream = new MemoryStream();
        // Export PDF using MemoryStream.
        service.ExportTo(report, stream, st);

        Response.Headers.Add("Content-Disposition", "attachment;filename=card.pdf");
        return File(stream.ToArray(), "application/pdf");
    }

它创建一个 pdf 文件,我使用 Nuget:stimulsoft.reports.engine.netcore

并且不需要ViewerEvent()PrintPage.cshtml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 2022-01-13
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    相关资源
    最近更新 更多