ReportView localreport render to htm

  private static void EnableFormat(ReportViewer viewer, string formatName)
        {
            const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;

            FieldInfo m_previewService = viewer.LocalReport.GetType().GetField
              (

                 "m_previewService",
                          Flags
                          );
            MethodInfo ListRenderingExtensions = m_previewService.FieldType.GetMethod

                (
                        "ListRenderingExtensions",
                                 Flags
            );
            object previewServiceInstance = m_previewService.GetValue(viewer.LocalReport);
            IList extensions = ListRenderingExtensions.Invoke(previewServiceInstance, null) as IList;
            PropertyInfo name = extensions[0].GetType().GetProperty("Name", Flags);
            foreach (object extension in extensions)
            {
                if (string.Compare(name.GetValue(extension, null).ToString(), formatName, true) == 0)
                {
                    FieldInfo m_isVisible = extension.GetType().GetField("m_isVisible", BindingFlags.NonPublic | BindingFlags.Instance);
                    FieldInfo m_isExposedExternally = extension.GetType().GetField("m_isExposedExternally", BindingFlags.NonPublic | BindingFlags.Instance);
                    m_isVisible.SetValue(extension, true);
                    m_isExposedExternally.SetValue(extension, true);
                    break;
                }
            }

        }

 

 private void button2_Click(object sender, EventArgs e)
        {
            // Ask user where to save
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "MS Word (*.htm)|*.htm|All files (*.*)|*.*";
            DialogResult dr = saveDialog.ShowDialog();
            if (dr == DialogResult.Cancel)
            {
                return;
            }
            // Create a report
            Warning[] warnings;
            using (FileStream stream = File.Create(saveDialog.FileName))
            {
                EnableFormat(this.reportViewer1, "HTML4.0");
                this.reportViewer1.LocalReport.Render(
                    "HTML4.0",
                    @"<DeviceInfo><ExpandContent>True</ExpandContent></DeviceInfo>",
                    (CreateStreamCallback)delegate { return stream; },
                    out warnings);
            }
        }

 

posted @ 2010-07-18 08:24  leslie116  阅读(630)  评论(0编辑  收藏  举报