ilich / MvcReportViewer

ASP.NET MVC Html Helpers for ReportViewer Control.
MIT License
282 stars 131 forks source link

Export filename and export format types #197

Open jonokhor opened 7 years ago

jonokhor commented 7 years ago

Resolves #162. Resolves #144.

This is what we're currently using at my company. With #144, a decision was made to specify the export format types to display rather than the types to hide because it is more useful to us to specify it that way.

Happy to take any feedback.

jk464479460 commented 6 years ago

Thanks for fixing this issue. But I found one issue for specific format types. Test Data: var ctrlSetting = new ControlSettings() { VisibleExportFormats=new ReportFormat[] { ReportFormat.Pdf, ReportFormat.Word, ReportFormat.ExcelOpenXml} }; ... @Html.MvcReportViewer(...).ControlSettings(ctrlSetting); Test Result: Word will didn't show in export list. I change ReportViewerExtensions.cs, ` private static void HideRenderingExtensions(Report report, ControlSettings controlSettings) {

        report.ListRenderingExtensions().ToList().ForEach(item=> {
            if (controlSettings.VisibleExportFormats.Count(i=>i.ToString().ToUpper()==item.Name.ToUpper())>0)
            {
                var isVisiblePrivateField = item.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                if (isVisiblePrivateField != null)
                {
                    isVisiblePrivateField.SetValue(item, true);
                }
            }
            else
            {
                var isVisiblePrivateField = item.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                if (isVisiblePrivateField != null)
                {
                    isVisiblePrivateField.SetValue(item, false);
                }
            }
        });

        //var hiddenRenderingExtensions = report.ListRenderingExtensions()
        //        .Where(renderingExtension =>
        //            controlSettings.VisibleExportFormats.All(exportFormat =>
        //            !renderingExtension.Name.EqualsIgnoreCase(exportFormat.ToString())));

        //foreach (var renderingExtension in hiddenRenderingExtensions)
        //{
        //    var isVisiblePrivateField = renderingExtension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
        //    if (isVisiblePrivateField != null)
        //    {
        //        isVisiblePrivateField.SetValue(renderingExtension, false);
        //    }
        //}
    }`

It will work.