动态修改rdlc报告(c#)

时间:2015-11-17 17:12:32

标签: report rdlc

我有一个存储在数据库中的字体,我必须用该字体设置我的所有文件。 我设置绑定我的报告:

FormBudgReelReport form = new FormBudgReelReport();
form.Viewer.LocalReport.ReportEmbeddedResource = _NomRessourceRpt;
form.Viewer.LocalReport.DataSources.Add(source);
form.ShowDialog();

如果我可以将我的rdlc加载为XmlDocument,我知道如何做到这一点,但有没有办法做到这一点? 我无法使用像=Parameters!Police.Value这样的公式,因为我有很多报告需要更改。

2 个答案:

答案 0 :(得分:0)

  

如果我可以将我的rdlc加载为XmlDocument,我知道如何做到这一点,但有没有办法做到这一点?

在解决方案资源管理器中,您可以右键单击.rdlc文件,然后选择< 打开方式... >选择编辑器。

enter image description here

更新:

  

我正在寻找一种方法来加载我的rdlc在xmlDocument对象中,然后在运行时编辑xml节点。

以下代码段可帮助您将.rdlc报告文件从resources文件夹加载到Xml文档:

using System;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Resources;

 private void LoadRDLCFromResources()
 {
    //Declare variables
    XmlDocument objXmlDocument = new XmlDocument();
    Byte[] byteArray;
    Stream objStream = null;
    ResourceManager resourceManager = null;

    try
    {
        // Initialize ResourceManager object
        resourceManager = new ResourceManager("your_namespace_name.Properties.Resources", GetType().Assembly);
        if (resourceManager != null)
        {
            //Load the resource file "Sample.rdlc" into ByteArray
            byteArray = (Byte[])resourceManager.GetObject("Sample");
            if (byteArray != null)
            {
                //Load this bytearray into MemoryStream
                objStream = new MemoryStream(byteArray);
                if (byteArray.Length > 0)
                {
                    //Load this stream object into XML document and  
                    //thus you get the rdlc file loaded as an XML 
                    //document. 
                    objXmlDocument.Load(objStream);

                    // Code for using this xml document as per your use
                }
            }
        }
    } 
    //MissingManifestResourceException is an exception thrown when the resource manager fails to initialize appropriately. In such case, please check the namespace name.
    catch (MissingManifestResourceException ex)
    {

        MessageBox.Show("Exception -> " + ex.Message,
           "Sample Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Exception -> " + ex.Message,
            "Sample Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    finally
    {
        // Clear the objects in finally block. This is required for memory management issues.
        // If xml document is not required further then clear it in the following manner
        if (objXmlDocument != null)
        {
            objXmlDocument.DocumentElement.RemoveAllAttributes();
            objXmlDocument.DocumentElement.RemoveAll();   

            objXmlDocument.RemoveAll();
        }
        //Clear the memory stream object 
        if (objStream != null)
        {
            objStream.Flush();
            objStream.Close();
            objStream.Dispose();
        }
        // Clear resource manager 
        resourceManager.ReleaseAllResources();
    }
}

来源:How to load a rdlc file from resources folder into an XML document dynamically?

答案 1 :(得分:0)

好的! 我可以通过以下代码将我的rdlc加载为xmlDocument:

Stream st = this.GetType().Assembly.GetManifestResourceStream(_NomRessourceRpt);

// convert stream to string
StreamReader reader = new StreamReader(st);
string reportDef = reader.ReadToEnd();

XmlDocument document = new XmlDocument();
document.LoadXml(reportDef);

感谢您的帮助:)