//报表定义
ReportViewer reportViewer = new ReportViewer();
//报表数据源
ReportDataSource datasource = null;
//设置数据
DataSet ds = null; //请自行绑定数据
//指定报表模板地址
reportViewer.LocalReport.ReportPath = Server.MapPath("temp.rdlc");
//报表数据源设置
datasource = new ReportDataSource("TshirtMugData_Tshirt", ds.Tables[0]);
// 报表参数
ReportParameter[] reportpara = new ReportParameter[2];
reportpara[0] = new ReportParameter("Date", Date);
reportViewer.LocalReport.SetParameters(reportpara);
reportViewer.Visible = true;
// 写Excel文件
byte[] bytes = reportViewer.LocalReport.Render("Excel", null, out strMimeType, out strEncoding, out strFileNameExtension, out strStreamIds, out warnings);
if (!System.IO.File.Exists(filepath + filename))
{
using (System.IO.FileStream fs = new System.IO.FileStream(filepath + filename, System.IO.FileMode.Create))
{
//写入文件
fs.Write(bytes, 0, bytes.Length);
}
}