如何使用 ASP.NET core Web api 从水晶报表导出 pdf

编程


大家好,

我正在创建一个使用reactjs作为前端、asp.net 6.0作为后端的应用程序,我想在水晶报表中创建报告并使用asp.net core web api将该报告导出为PDF和Excel。

我在asp.net中编写了代码,但出现了一些错误
ReportDocument reportDocument = new ReportDocument();

我还发送了错误屏幕截图和下面的代码..

代码如下:

网络平台
public async Task<iactionresult> GenerateReport()
{
    try
    {
        string rootDirectoryPath = _hostingEnvironment.ContentRootPath;
        string reportPath = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports" + "\\AccountReport.rpt");
        ReportDocument reportDocument = new ReportDocument();
        reportDocument.Load(reportPath);

        System.IO.MemoryStream stream = new System.IO.MemoryStream();
       
        stream.Seek(0, System.IO.SeekOrigin.Begin);
       
        return File(stream, "application/pdf", "report.pdf");
    }
    catch (Exception ex)
    {
        
        return StatusCode(500, $"Internal server error: {ex.Message}");
    }
}

Error is below :

FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

该系统找不到指定的文件。

请帮我解决这个问题..

谢谢

我尝试过的:

我已经安装了所有相关的 Nuget Packges

解决方案1

已解决:适用于 Visual Studio 和 .NET Core 5 的 Crystal Reports… – SAP 社区[^]

该线程表明 Crystal Reports 不支持 .NET Core / .NET 5+; 它仅适用于 .NET Framework。

您需要在 .NET Framework 中重写应用程序,或者选择不同的报告工具。

您可以尝试联系 SAP,看看他们是否有任何支持 .NET 的更新计划,但该线程中至少有一条评论表明他们明年将放弃对 Visual Studio 的所有支持,因此他们的立场不太可能发生改变。

コメント

タイトルとURLをコピーしました