This is a migrated thread and some comments may be shown as answers.

Create a report of styles in an external style sheet

2 Answers 252 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 15 Mar 2011, 12:24 PM
Hi

We're creating a reporting application that uses a shared external style sheet across a number of reports.

I'd like to create a report that lists all the styles in the stylesheet - I thought I'd try something like this in the report constructor (pseudo code only):

Add the stylesheet file to the reports
Use the collection of styles as an object data source
Create a conditional formatting rule that uses a named style for each row.

I can't find a way to enumerate the styles that are added by external style sheet - this is my code in the report constructor:

ess = new ExternalStyleSheet(path);
ExternalStyleSheets.Add(ess);
 
foreach (StyleRule style in StyleSheet)
{
    //do something with styles;
}

no styles are found by the foreach loop...

Am I doing something wrong? Can my approach work?

thanks
Andy

2 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 17 Mar 2011, 06:30 PM
Hello Andy,

Can I ask you what exactly do you want to do after you get an external style? Do you want to iterate the style rules?

One approach to load your external style is to use XmlSerializer to deserialize your external StyleSheet. You will have StyleSheet object which is a collection with all style rules.
I prepared a small sample for you to demonstrate this approach:

            byte[] file = File.ReadAllBytes("StyleSheet.xml");
            using (MemoryStream ms = new MemoryStream(file))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(StyleSheet));
                StyleSheet styleSheet = (StyleSheet)serializer.Deserialize(new StreamReader(ms));
                foreach (StyleRule rule in styleSheet)
                {
                    BorderColor color = rule.Style.BorderColor;
                    color.Top.ToString();
                }
            }

More information about styles you can find in the following help resources:


Hope this helps.

All the best,
Hristo
the Telerik team
0
Andy
Top achievements
Rank 1
answered on 31 Mar 2011, 01:33 PM
thanks, that's just what I needed...

The point was to create a collection of styles from the stylesheet that could be iterated by a report and the style for each item applied to a the report field to visually show each style and its characteristics.
Tags
General Discussions
Asked by
Andy
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Andy
Top achievements
Rank 1
Share this question
or