我已经在Visual Studio 2019中使用存储过程创建了一个水晶报表,该报表具有多个子报表和一个参数。我可以从报表中预览它。现在,我想预览它或使用ASP.NET MVC C#生成PDF。但是我找不到办法。谁能帮忙?
伙计们,我对此进行了进一步研究,并找到了解决方案。它完美地工作而无需创建数据表。干杯。
public ActionResult DownloadPortfolio()
{
if (Session["user"] == null)
{
return RedirectToAction("Login", "Users");
}
User user = (User)Session["user"];
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Reports"), "InvestorPortfolio.rpt"));
rd.SetDatabaseLogon(DbKeyManager.DbUser, DbKeyManager.DbPass, DbKeyManager.DbSource, DbKeyManager.DbName);
rd.SetParameterValue("@investorcode", user.InvestorCode);
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
rd.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;
rd.PrintOptions.ApplyPageMargins(new CrystalDecisions.Shared.PageMargins(5, 5, 5, 5));
rd.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", user.InvestorCode+"Portfolio-Statement.pdf");
}
您可以尝试生成pdf报告。
List<data> Data = //Data From stored procedure
rpt_Portfolio_finance rpt = new rpt_Portfolio_finance();
rpt.Load();
rpt.SetDataSource(Data);
Stream s = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(s, "application/pdf");