从 ReportViewer 和 SQL Server 报表创建 Excel 文件
我有一个 Web 应用程序,它有一个网格,向用户显示分页数据列表。用户需要将结果下载到 Excel 电子表格的选项。但是,正如我所说,网格中显示的项目是分页的,我需要整个结果集。此外,我只显示每个项目大约 7 个字段,而电子表格将包含一个项目的所有 20 多个字段。所以,我并不是在寻找网格到 Excel 的解决方案。
我正在尝试做一些我以前实际工作过的事情。在以前的雇主(源代码不可用)中,我们有一个应用程序,其中包含作为 RDLC 文件的 SQL Server 报告。我们将在代码中创建一个 ReportViewer 控件 (var reportViewer = new ReportViewer())。然后,我们将报告绑定到控件,为其提供数据源,然后以我们需要的任何格式呈现结果。就我而言,我需要一个 Excel 文件,然后将 ExcelFile 在响应中流式传输回用户。
我使用的是 MVC3,因此我将返回 Excel 文件作为 FileContentResult。我已经在互联网上搜索了一天,但找不到我要找的东西。
I have a web application that has a grid displaying a paged list of data to the user. The user needs the option to download the results to an Excel spreadsheet. However, the items displayed in the grid are, like I said, Paged and I need the whole result set. In addition, I'm only displaying about 7 fields per item, whereas the spreadsheet will contain all 20+ fields for an item. So, I'm not looking for a grid-to-Excel solution.
I'm trying to do something that I've actually worked with before. At a previous employer (source code not available), we had an application that contained SQL Server report as an RDLC file. We would create a ReportViewer control in code (var reportViewer = new ReportViewer()). Then, we would bind the report to the control, give it a datasource and then render the results in whatever format we needed. In my case I need an Excel File, and then stream the ExcelFile back to the user in the response.
I'm using MVC3, so I'll be returning the Excel file as a FileContentResult. I've been searching the internet for a day and can't quite find what I'm looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
控制器动作。格式参数应为“EXCEL”。
从任何报告创建 FileContentResult 的帮助程序方法。
编辑:忘记调用帮助功能。哎呀。
Controller action. The format parameter should be 'EXCEL'.
Helper method that creates a FileContentResult from any Report.
Edit: Forget to call the help function. Oops.
您可以尝试如下所示的操作...我们从数据访问级别填充对象列表,然后将该对象列表传递给如下所示的操作...
You might try something like the following... We fill a list of objects from our data access level and then pass that list of objects to something like the following...