![](/img/trans.png)
[英]ReportViewer, Index outside the bounds of array (RDLC report) C#
[英]Export RDLC report to Excel without ReportViewer C#
我试图在没有 ReportViewer 的情况下将 RDLC 报告导出到 Excel。 我使用的是 Microsoft Visual Studio 2010 和 Microsoft SQL Server 2008 R2。 以下是我的步骤:
按照向导步骤 -- 来自 web.config 的 ConnectionString -- 存储过程作为创建报告的源。 我做了 2 个参数,即StartDate
和EndDate
。
这是我的存储过程:
CREATE PROCEDURE mySP (@StartDate datetime, @EndDate datetime) AS BEGIN SELECT * FROM myTable WHERE TheDate >= @StartDate AND TheDate <= @EndDate END
为报告添加一些字段
这些是我创建 RDLC 报告的步骤。 我从VS 2010 和 SQL Server 2008 中的 Create RDLC Report 中获取了源代码
问题是:如何在不使用 ReportViewer 的情况下导出我刚刚设计的 RDLC 报告? 我的网页上有一个按钮,比如说:“导出到 Excel”。
谢谢你。
这是代码:
Warning[] warnings;
string[] streamids;
string mimeType, encoding, extension;
string filenameToSave = "test.xlsx";
LocalReport report = new LocalReport();
/*
define here everything about your report: rdlc file, parameters, options etc.
*/
FileStream newFile = new FileStream(filenameToSave, FileMode.Create);
string renderFormat = (filenameToSave.EndsWith(".xlsx") ? "EXCELOPENXML" : "Excel");
byte[] bytes = report.Render(renderFormat, null, out mimeType, out encoding, out extension, out streamids, out warnings);
newFile.Write(bytes, 0, bytes.Length);
newFile.Close();
使用 LocalReport.Render(), 方法如下
笔记
var viewer = new Microsoft.Reporting.WebForms.ReportViewer( ... );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.