WEB Form ReportViewer 自製匯出功能
ReportViewer在WEB FORM的TOOL BAR 有個匯出的功能,有USER反應他在IE6執行時,匯出會多一產生一個空白頁。
於是我自製了一個匯出的功能,來取代原TOOL BAR 的匯出
/// <summary>
/// 呼叫此function將rdl檔賦予資料後進行匯出
/// </summary>
/// <param name="pType">支援PDF、Excel、Image等格式</param>
public void ExportReport(string pType,string FileName)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string deviceInfo;
deviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";
byte[] bytes = ReportViewer.ServerReport.Render(pType, null, out mimeType, out encoding
, out extension,out streamids, out warnings);
Response.Clear();
// 使用 UTF8 編碼
Response.HeaderEncoding = System.Text.Encoding.UTF8;
Session.CodePage = 65001;
Response.Charset = "UFT8";
Response.ContentType = mimeType;
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}.{1}", FileName, extension));
Response.BinaryWrite(bytes);
Response.End();
}
protected void btnExport_Click(object sender, EventArgs e)
{
ExportReport("PDF", "Terminal");
}