Loading styles programatically from a .sts file

Stimulsoft Reports.WEB discussion
Post Reply
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Loading styles programatically from a .sts file

Post by John »

Hallo Support,

I have a lot of templates saved as .cs classes in my project. In each template there is a list of styles defined which I also keep in a Styles.sts file. If I have to make a global change, for example, my "StyleNormal" should now be 9pt font size instead of 8pt it would be great if I only had to make the change once in my sts file, rather than opening each template and making the change there.
As I understand it, to do this I have to load the styles from Styles.sts at runtime and replace the styles in my template.
This is the code I have tried:

// load my embedded file into a stream
Stream normalStyles = myUtils.GetResourceAsStream("XXX.Styles.sts");

// load my template generically as there are lots of them
Type retType = typeof(T);
var template = (T)Activator.CreateInstance(retType);

// convert to StiReport
StiReport report = template as StiReport;

// remove the existing styles
report.Styles.Clear();

// reset pointer
normalStyles.Position = 0;

// load all styles from the file
report.Styles.Load(this.normalStyles);

This doesn't seem to work as I would have expected so I must be doing something wrong.
For example, when I DON'T load the styles (in the last line of code) and let my report render, the debugger tells me that the Styles collection is empty but when I view the report as a pdf it is still formatted correctly. How does the report still know the style information even though all the styles have been cleared?

When I load the styles from my Styles.sts file there is a problem for any styles which contain a Description node - this text is then used as the name of the style.

Is what I am trying to do possible and if so, how can I be sure that the styles in my template .cs class are completely overwritten?

Thanks and regards,

John Kitching

[P.S. Using latest .net version of Stimulsoft]
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Loading styles programatically from a .sts file

Post by Alex K. »

Hello,

We check your code and it works.
Please send us a sample project which reproduces the issue for analysis.

Thank you.
Post Reply