限定ReportViewr匯出格式 (三)

  • 691
  • 0
  • C#
  • 2014-07-16

摘要:限定ReportViewr匯出格式 (三)

限定ReportViewr匯出格式,又來了 !為什麼呢?

因為vs2010的reportingviewer,改成圖型按鈕的下拉選項了surprise

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Reflection;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

        #region "限定ReportViewr匯出格式"
        /// 限制報表匯出格式 
        /// 傳入ReportViewr物件
        ///匯出格式:格式與格式之間以"|"符號分隔 
        ///     XML
        ///     CSV
        ///     PDF 
        ///     ATOM
        ///     EXCEL 
        ///     WORD 
        ///     IMAGE 
        ///     RGDI 
        ///     MHTML
        ///     TIFF
        ///     Excel
        ///匯出時的檔名
        /// 
        ///
        public static void ReportViewer_ExportOption(Report report, string strRVExpFmt, string strRVExpName)
        {
            char[] separator1 = new char[] { '|' };

            string[] aryRVExpFmtList = strRVExpFmt.Split(separator1);

            var r = report.ListRenderingExtensions();
            foreach (RenderingExtension ext in r)
            {
                FieldInfo fiVisible = ext.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance);
                fiVisible.SetValue(ext, aryRVExpFmtList.Contains(ext.Name));
            }
            //匯出時的檔名
            if (strRVExpName != "")
            {
                report.DisplayName = strRVExpName;
            }

        }

    
   
    protected void ReportViewer1_Load(object sender, EventArgs e)
    {
       ReportViewer_ExportOption(ReportViewer1.ServerReport, "PDF","報表名稱");

        
    }

    protected void ReportViewer1_Drillthrough(object sender, DrillthroughEventArgs e)
    {
        ReportViewer_ExportOption(e.Report, "PDF","報表名稱");
      
    }
}