将我的asp.net MVC模型数据导出到Excel工作表中

时间:2017-06-09 01:46:33

标签: c# asp.net asp.net-mvc export-to-excel asp.net-mvc-5

我的asp.net mvc web应用程序中有以下5个模型: -

 public partial class Anwer
    {
        public Anwer()
        {
            this.UserFormsAnswers = new HashSet<UserFormsAnswer>();
        }

        public int Id { get; set; }
        public string AnwerDesc { get; set; }
        public int QuestionID { get; set; }
        public bool Correct { get; set; }

        public virtual Question Question { get; set; }
        public virtual ICollection<UserFormsAnswer> UserFormsAnswers { get; set; }
    }
 public partial class Question
    {
        public Question()
        {
            this.Anwers = new HashSet<Anwer>();
        }

        public int Id { get; set; }
        public string QuestionDesc { get; set; }
        public int Order { get; set; }
        public bool Active { get; set; }

        public virtual ICollection<Anwer> Anwers { get; set; }
    }
 public partial class UserFormsAnswer
    {
        public int Id { get; set; }
        public int AnswerID { get; set; }
        public int FormID { get; set; }

        public virtual Anwer Anwer { get; set; }
        public virtual UsersForm UsersForm { get; set; }
    }
   public partial class UsersForm
    {
        public UsersForm()
        {
            this.UserFormsAnswers = new HashSet<UserFormsAnswer>();
        }

        public int Id { get; set; }
        public string UserID { get; set; }
        public string UserName { get; set; }
        public System.DateTimeOffset DateSubmitted { get; set; }

        public virtual AspNetUser AspNetUser { get; set; }
        public virtual ICollection<UserFormsAnswer> UserFormsAnswers { get; set; }
    }

 public partial class AspNetUser
    {
        public AspNetUser()
        {
            this.UsersForms = new HashSet<UsersForm>();
        }

        public string Id { get; set; }

        public string UserName { get; set; }

        public virtual ICollection<UsersForm> UsersForms { get; set; }
    }

简而言之,我有一个存储考试信息的UserForms,而UserFormsAnswer是每个考试的actula答案。我有问题和答案。

现在我尝试将以下值导出到Excel工作表中: -

user name | Question1 ID | Question2 ID | Question3 ID | ....
UserA     | True         | False        | True         |.....
UserB     | True         | True         | True         |.....

所以有人可以如上所示,如何将数据分组,然后将数据导出到excel表中供用户下载和阅读?

0 个答案:

没有答案