使用Crystal Report导出对象列表

时间:2018-10-08 09:12:21

标签: c# asp.net crystal-reports export

这是我的表结构:

table structure

我有这样的对象

public partial class student
{
    public int StudId { get; set; }
    public string Name { get; set; }
    public string Course { get; set; }

    public List<Book> ListOfBook { get; set; }

}

public partial class Book
{
    public int BookId { get; set; }
    public string BookName { get; set; }
}

我已经初始化了我的学生对象

List<student> newStudent = new List<student>();
using (myDbEntity db = new myDbEntity())
{
    newStudent = db.Student.ToList();
}

ReportDocument myReport = new ReportDocument();
myReport.Load(Path.Combine(Server.MapPath("~/Reports"), "myReport.rpt"));
myReport.SetDataSource(new[] { newStudent.First() });

try
{
    Stream stream = myReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    stream.Seek(0, SeekOrigin.Begin);
    return File(stream, "applicaion/pdf", "ExportReport.pdf");
}
catch (Exception ex)
{
    throw ex;
}

我只能导出一位学生的报告。每个文档一页。 这是我的问题,该怎么做,第一页是第一位学生,第二页是第二位学生。

0 个答案:

没有答案
相关问题