开发者

SSRS2008: LocalReport export to HTML / fragment

I need local RDL report to be exp开发者_高级运维orted to HTML, preferably HTML fragment. In 2005 it wasn't officially supported but there was a trick. In SSRS2008 they seem to drop this support (there's no HTML extension in the supported extensions when enumerating using reflection) and use RPL instead which is a binary format that I doubt someone will be happy to parse. Actually it's doesn't seem to be about HTML at all.

Now, is there a way to render HTML using SSRS2008 local report?

Notice that I use VS2008 but with reporting assemblies installed from VS2010 Beta 2 reportviewer.


I found a way, but it's not very good. Export report to mhtml (it's supported by SSRS2008) Then use System.Windows.Forms.WebBrowser for render mhtml. In wb.DocumentText property will be full html page.

It's not very good, because you need a file (as url for WebBrowser). And also, if I use WebBrowser in ASP.NET application, I need to process it in another thread, with STA ApartmentState.


Looking for the same thing. I suppose I suppose we could try to grab the rendered output of the ReportViewer somehow with reflection?

I might play around with it in a little bit to see what I can come up with.


If you can get the mht, you can extract it's content with MIMER.

There is a nu-get package here (MIMER will require .NET Framework 3.5):
https://www.nuget.org/packages/MIMER/

using System;
using System.Collections.Generic;
using System.Windows.Forms;


using MIMER;


namespace MimerTest
{


    // https://github.com/smithimage/MIMER/blob/master/MIMERTests/MHT/MhtTests.cs
    // https://github.com/smithimage/MIMER/
    static class Program
    {



        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (false)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }


            System.IO.Stream m_Stream;
            string path = @"d:\USERNAME\documents\visual studio 2013\Projects\MimerTest\MimerTest\whatismht.mht";

            System.IO.FileInfo finf = new System.IO.FileInfo(path);
            m_Stream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            var reader = new MIMER.RFC2045.MailReader();
            MIMER.IEndCriteriaStrategy endofmessage = new MIMER.RFC2045.BasicEndOfMessageStrategy();
            var message = reader.ReadMimeMessage(ref m_Stream, endofmessage);

            System.Collections.Generic.IDictionary<string,string> allContents = message.Body;

            string strFile = allContents["text/html"];


            foreach (System.Collections.Generic.KeyValuePair<string,string> kvp in allContents)
            {
                System.Console.WriteLine(kvp.Key);
                System.Console.WriteLine(kvp.Value);
            }



            System.Console.WriteLine(" --- Press any key to continue --- ");
            System.Console.ReadKey();
        }
    }
}

In the 2005 ReportViewer, you can enable HTML via reflection:

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;
         }
     }
 }

Usage:

var Viewer = new Microsoft.Reporting.WebForms.ReportViewer();
EnableFormat(Viewer, "HTML4.0");

You might also find this interesting:

http://www.codeproject.com/Articles/23966/Report-Viewer-generate-reports-MS-Word-formats

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜