0

使用 MVC3 和 razor 以及 NuGet Doddle Report,我构建了一个很好的报告,可以在 Excel 中打开一个视图模型。我想允许用户在将报告导出到 Excel 之前提供过滤器并对视图进行排序。是否有推荐的方法或我可以查看的资源?

谢谢!

编辑

创建报告的控制器代码:

public ReportResult CaseReport()
        {
        var viewModel = new CasesReportViewModel();


        var query = (from c in db.Cases
                     join customer in db.Customers on c.CustomerID equals customer.CustomerID
                     join category in db.CaseCategories on c.CaseCategoryID equals category.CaseCategoryID
                     join tech in db.Technicians on c.TechnicianID equals tech.TechnicianID
                     join engine in db.EngineModels on c.EngineModelID equals engine.EngineModelID
                     select new CasesReportViewModel()
                        {
                            CustomerName = c.Customer.CustomerName,
                            UserName = c.UserName,
                            PromoID = tech.PromoID,
                            EngineModelName = engine.EngineModelName,
                            CaseNumber = c.CaseNumber,
                            BMSWorkorder = c.BMSWorkorder,
                            CaseStatus = c.CaseStatus,
                            OpenedBy = c.OpenedBy,
                            OpenedDate = c.OpenedDate,
                            ClosedBy = c.ClosedBy,
                            ClosedDate = c.ClosedDate,
                            CategoryName = category.CategoryName,
                            CallerFirstName = c.CallerFirstName,
                            CallerLastName = c.CallerLastName,
                            AdditionalContact = c.AdditionalContact,
                            Qualified = c.Qualified,
                            Description = c.Description,
                            ESN = c.ESN,
                            Mileage = c.Mileage,
                            DateInService = c.DateInService,
                            ESTR = c.ESTR,
                            EDS = c.EDS
                        });


        var report = new Report(query.ToReportSource());

        //customize fields
        report.TextFields.Title = "Case Report";
        AppHelpers app = new AppHelpers();
        report.TextFields.Header = "Report Date = " + Convert.ToString(app.GetEasternTime());
        report.TextFields.Footer = "Copyright 2012";

        //data fields
        report.RenderHints.BooleanCheckboxes = true;

        report.DataFields["CustomerName"].DataFormatString = "{0:c}";
        report.DataFields["UserName"].DataFormatString = "{0:c}";
        report.DataFields["EngineModelName"].DataFormatString = "{0:c}";
        report.DataFields["CaseNumber"].DataFormatString = "{0:c}";
        report.DataFields["BMSWorkorder"].DataFormatString = "{0:c}";
        report.DataFields["CategoryName"].DataFormatString = "{0:c}";
        report.DataFields["CaseStatus"].DataFormatString = "{0:c}";
        report.DataFields["OpenedBy"].DataFormatString = "{0:c}";
        report.DataFields["OpenedDate"].DataFormatString = "{0:d}";
        report.DataFields["ClosedBy"].DataFormatString = "{0:c}";
        report.DataFields["ClosedDate"].DataFormatString = "{0:d}";
        report.DataFields["CallerFirstName"].DataFormatString = "{0:c}";
        report.DataFields["CallerLastName"].DataFormatString = "{0:c}";
        report.DataFields["AdditionalContact"].DataFormatString = "{0:c}";
        report.DataFields["Qualified"].DataFormatString = "{0:c}";
        report.DataFields["Description"].DataFormatString = "{0:c}";
        report.DataFields["ESN"].DataFormatString = "{0:c}";
        report.DataFields["Mileage"].DataFormatString = "{0:c}";
        report.DataFields["DateInService"].DataFormatString = "{0:d}";
        report.DataFields["ESTR"].DataFormatString = "{0:c}";
        report.DataFields["EDS"].DataFormatString = "{0:c}";

        return new ReportResult(report, new ExcelReportWriter(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileName = "CaseReport" };

        }
4

0 回答 0