Hello,
I’m using Aspose Word 17.11 version.
I’ve defined styles in Word Template. I’m loading document with template
My code is below:
var document = new Document(@"Word_Template.dotx");
var documentTheme = document.Theme;
document.AttachedTemplate = "Word_Template.dotx";
document.AutomaticallyUpdateSyles = true;
var documentBuilder = new DocumentBuilder(document);
.
In a template, I’ve many styles but say, I’m interested in below styles
“Heading4,Content Heading 3 Sub-heading”,
“Case study text”
When I loop through document Styles, I’m getting defined styles.
(Style Name) - (Style Type)
“Heading 4” - “Paragraph”
“Heading 4 Char” - “Character”
“Case study text” - “Paragraph”
I’ve tried to apply say, heading 4 in below manners:
I’ve DocumentBuilder extension method has below:
- With Style Identifier and Style Name
public static void WriteByStyleName(this DocumentBuilder documentBuilder, string text, string styleName, StyleIdentifier styleIdentifier = StyleIdentifier.BodyText){
documentBuilder.ParagraphFormat.StyleIdentifier = styleIdentifier
documentBuilder.ParagraphFormat.Style.Name = styleName;
documentBuilder.Writeln(text);
documentBuilder.ParagraphFormat.Style.Name = "Body Text";
documentBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.BodyText
}
I apply in this manner:
public static void WritelnHeading4(this DocumentBuilder documentBuilder, string text)
{
documentBuilder.WriteByStyleName(text, "Heading 4", StyleIdentifier.Heading4, true);
}
documentBuilder.WritelnHeading4("My Heading 4 Text")
and so on..
When I inspect word document, the problem is
with heading 4, paragraph’s style is Heading 4, Content Heading 3 Sub-heading, but it is not bold and
with “Case study text”, paragraph has style but font color is not applied.
- With assigning Style object
public static void WriteByStyleName(this DocumentBuilder documentBuilder, string text, string styleName, StyleIdentifier styleIdentifier = StyleIdentifier.BodyText)
{
Style style = documentBuilder.Document.Styles[styleName];
if (style.Type == StyleType.Paragraph)
{
documentBuilder.CurrentParagraph.ParagraphFormat.Style = style;
documentBuilder.Writeln(text);
documentBuilder.CurrentParagraph.ParagraphFormat.Style =
documentBuilder.Document.Styles["Body Text"];
}
}
When I inspect word document, the problem is
with heading 4,paragraph’s style is Heading 4, Content Heading 3 Sub-heading, but it is not bold and
with “Case study text”, paragraph’s style is “Normal”
How can I resolve this issue? I’ve heading isssues throughout the document. They seems like they applied but Font Styles(e.g. Bold) didn’t applied.
What is difference between documentBuilder.CurrentParagraph.ParagraphFormat and documentBuilder.ParagraphFormat?
Thanks.