如果是使用的网页嵌入ReportView的方式的,可以在aspx上加入js来控制导出格式:
<script src="js/jquery-1.9.0.js"></script> <script type="text/javascript"> // 使用jquery 1.9 主要是为了兼容ie 6/7/8 $(document).ready(function(e) { $("#ReportViewer1_ctl01_ctl05_ctl00 option[value='XML']").remove(); $("#ReportViewer1_ctl01_ctl05_ctl00 option[value='CSV']").remove(); $("#ReportViewer1_ctl01_ctl05_ctl00 option[value='MHTML']").remove(); $("#ReportViewer1_ctl01_ctl05_ctl00 option[value='EXCELOPENXML']").remove(); $("#ReportViewer1_ctl01_ctl05_ctl00 option[value='IMAGE']").remove(); $("#ReportViewer1_ctl01_ctl05_ctl00 option[value='WORDOPENXML']").remove(); }); </script>
如果是asp.net 可以使用,我没有试这个
public static class ReportViewerExtensions { public static void SetExportFormatVisibility(this ReportViewer viewer, ReportViewerExportFormat format, bool isVisible) { string formatName = format.ToString(); const System.Reflection.BindingFlags Flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance; System.Reflection.FieldInfo m_previewService = viewer.LocalReport.GetType().GetField("m_previewService", Flags); System.Reflection.MethodInfo ListRenderingExtensions = m_previewService.FieldType.GetMethod("ListRenderingExtensions", Flags); object previewServiceInstance = m_previewService.GetValue(viewer.LocalReport); IList extensions = (IList)ListRenderingExtensions.Invoke(previewServiceInstance, null); System.Reflection.PropertyInfo name = extensions[0].GetType().GetProperty("Name", Flags); //object extension = null; foreach (var ext in extensions) { if ((string.Compare(name.GetValue(ext, null).ToString(), formatName, true) == 0)) { System.Reflection.FieldInfo m_isVisible = ext.GetType().GetField("m_isVisible", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); System.Reflection.FieldInfo m_isExposedExternally = ext.GetType().GetField("m_isExposedExternally", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); m_isVisible.SetValue(ext, isVisible); m_isExposedExternally.SetValue(ext, isVisible); break; } } } } public enum ReportViewerExportFormat { Excel, PDF }
Simple to use.. ReportViewer1.SetExportFormatVisibility(ReportViewerExportFormat.PDF, false);