如何从反序列化的rdlc文件中更改rdlc报告项?

时间:2022-01-15 08:15:19

i want to find and change properties of report item element values in rdlc file. i deserialized ReportDefinition.xsd with xsd.exe tool :

我想在rdlc文件中查找和更改报表项元素值的属性。我使用xsd.exe工具反序列化ReportDefinition.xsd:

using (TextReader textReader = new StreamReader(RdlcPath, Encoding.UTF8))
        {
            var serializer = new XmlSerializer(typeof(SampleRDLSchema.Report));
            Report instance = (SampleRDLSchema.Report)serializer.Deserialize(textReader);
            textReader.Close();
        }

but now how i can get change in report item element values?(for example change Tablix width or textbox content)

但现在我如何才能更改报表项元素值?(例如更改Tablix宽度或文本框内容)

1 个解决方案

#1


1  

Like Jamie F stated, it would be easier to use formulas and expressions for the properties in the report. However, if you insist of doing it through XML manipulation, consider changing the xml instead of a deserialized object. The reason I say this is because it's cleaner. With the deserialized object you would have to do a loop, check if each object is the node you want, then continue this process until you have found the node you desire.

像Jamie F所说的那样,在报告中使用公式和表达式更容易。但是,如果您坚持通过XML操作来执行此操作,请考虑更改xml而不是反序列化对象。我说这个的原因是因为它更干净。使用反序列化对象,您必须执行循环,检查每个对象是否是您想要的节点,然后继续此过程,直到找到所需的节点。

If the object is serialized and is in XML format as, say a string, you can simply use XElement to quickly grab things you want. Example: I use this to grab the width of the report from it's report definition (file xml string).

如果对象是序列化的并且是XML格式的,比如字符串,您可以简单地使用XElement快速获取所需的内容。示例:我使用它从报表定义(文件xml字符串)中获取报表的宽度。

public String GetWidth()
{
     XElement Report = XElement.Parse(this._ReportDefinition);
     return Report.Element({http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Width").Value;
}

Or Another Example:

或者另一个例子:

    // The grabs the names of all tablix report items from the report definition.
    public String GetReportItemName(String DataSetName)
    {
        XElement Report = XElement.Parse(this._ReportDefinition);

        String ReportItemName = String.Empty;
        XElement Body = Report.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Body");
        XElement ReportItems = Body.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}ReportItems");
        foreach (XElement ReportItem in ReportItems.Elements())
        {
            if (ReportItem.Name == "{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Tablix")
            {
                String Name = ReportItem.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}DataSetName").Value;

                if (Name == DataSetName)
                {
                    ReportItemName = ReportItem.Attribute("Name").Value;
                }
            }
        }

        return ReportItemName;
    }

Hope this is of some help to you.

希望这对你有所帮助。

#1


1  

Like Jamie F stated, it would be easier to use formulas and expressions for the properties in the report. However, if you insist of doing it through XML manipulation, consider changing the xml instead of a deserialized object. The reason I say this is because it's cleaner. With the deserialized object you would have to do a loop, check if each object is the node you want, then continue this process until you have found the node you desire.

像Jamie F所说的那样,在报告中使用公式和表达式更容易。但是,如果您坚持通过XML操作来执行此操作,请考虑更改xml而不是反序列化对象。我说这个的原因是因为它更干净。使用反序列化对象,您必须执行循环,检查每个对象是否是您想要的节点,然后继续此过程,直到找到所需的节点。

If the object is serialized and is in XML format as, say a string, you can simply use XElement to quickly grab things you want. Example: I use this to grab the width of the report from it's report definition (file xml string).

如果对象是序列化的并且是XML格式的,比如字符串,您可以简单地使用XElement快速获取所需的内容。示例:我使用它从报表定义(文件xml字符串)中获取报表的宽度。

public String GetWidth()
{
     XElement Report = XElement.Parse(this._ReportDefinition);
     return Report.Element({http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Width").Value;
}

Or Another Example:

或者另一个例子:

    // The grabs the names of all tablix report items from the report definition.
    public String GetReportItemName(String DataSetName)
    {
        XElement Report = XElement.Parse(this._ReportDefinition);

        String ReportItemName = String.Empty;
        XElement Body = Report.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Body");
        XElement ReportItems = Body.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}ReportItems");
        foreach (XElement ReportItem in ReportItems.Elements())
        {
            if (ReportItem.Name == "{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Tablix")
            {
                String Name = ReportItem.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}DataSetName").Value;

                if (Name == DataSetName)
                {
                    ReportItemName = ReportItem.Attribute("Name").Value;
                }
            }
        }

        return ReportItemName;
    }

Hope this is of some help to you.

希望这对你有所帮助。