c#將ReportViewer數據導出到Excel
// 下載明細
//下載按鈕點擊事件
protected void downfile_Click(object sender, EventArgs e)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
try
{
//ReportViewer1 控件名稱
byte[] bytes = ReportViewer1.LocalReport.Render(
"Excel", null, out mimeType, out encoding, out extension,
out streamids, out warnings);
Response.OutputStream.Write(bytes, 0, bytes.Length);
//filename 導出文件名稱可自定義
Response.AppendHeader("Content-Disposition", "attachment; filename=Output.xls");
Response.ContentType = mimeType;
Response.Flush();
Response.End();
}
catch (Exception)
{
Response.Write("<script>alert('導出失敗,請確認!')</script>");
}
}`

浙公网安备 33010602011771号