- Code: Select all
class MPDocument : Spire.Doc.Document
{
public MPDocument()
{
...
ParagraphStyle style2 = new ParagraphStyle(this);
style2.ApplyBaseStyle(BuiltinStyle.Heading2);
style2.Name = CustomStyles.MPHeading2.ToString();
style2.CharacterFormat.Bold = false;
style2.CharacterFormat.Italic = false;
style2.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181);
this.Styles.Add(style2);
}
}
I have to apply a base style of Heading2 so that the table of contents properly reflects paragraphs using the custom style.
The problem I'm having is that even though I'm setting `Bold` and `Italic` to false, the paragraph still comes out in both bold and italics.
I've also tried to explicitly remove bold after setting the style, yet the text still remains bold (the same occurs for italics):
- Code: Select all
...
Paragraph subHeader = section.AddParagraph();
TextRange tr = subHeader.AppendText("Some header text");
subHeader.ApplyStyle(CustomStyles.MPHeading2);
tr.CharacterFormat.Bold = false;
It seems like the base style is overriding the bold and italic properties. If I don't apply a base style of Heading2 then it works fine, but my headers won't show in the table of contents so I can't solve it by avoiding that, unless there's another way to achieve the same effect which I'm unaware of.