//報表定義
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);
}
}