DOTX and Styles

Need some help. I’m loading up a document from a dotx file that has some styles in it. I’m able to access the style and when I debug I can confirm the style has the properties I expect it to but when the document is rendered, it doesn’t have that style applied. Here is a code except:

LoadOptions options = new LoadOptions();
options.LoadFormat = LoadFormat.Dotx;
_document = new Aspose.Words.Document(HttpContext.Current.Server.MapPath("~/Template.dotx"), options);

_documentBuilder = new Aspose.Words.DocumentBuilder(_document);
Aspose.Words.Style h2Style = Document.Styles["Organization Name"];
h2Style.Font.Bold = Document.Styles["Organization Name"].Font.Bold;
h2Style.Font.Size = Document.Styles["Organization Name"].Font.Size;
h2Style.Font.Color = Document.Styles["Organization Name"].Font.Color;
h2Style.Font.Italic = Document.Styles["Organization Name"].Font.Italic;
h2Style.ParagraphFormat.SpaceBefore = Document.Styles["Organization Name"].ParagraphFormat.SpaceBefore;
h2Style.ParagraphFormat.SpaceAfter = Document.Styles["Organization Name"].ParagraphFormat.SpaceAfter;
_documentBuilder.ParagraphFormat.Style = h2Style;
_documentBuilder.Writeln("OrganizationName");

That should have pumped out a line with red font, italics, and bold but it does not. Also, when I export/download the document created above I see all my style names but they don’t have any of the correct style info. Additionally, when I try explicitly try to set a style like this (similar to above), it does not work:

Aspose.Words.Style h2Style = Document.Styles["Organization Name"];
h2Style.Font.Color = System.Drawing.Color.Fuchsia;
h2Style.Font.Italic = true;

but when I use a “built in” style it does work, note the use of StyleIdentifier enum:

Aspose.Words.Style h2Style = Document.Styles[Aspose.Words.StyleIdentifier.Heading2];
h2Style.Font.Color = System.Drawing.Color.Fuchsia;

h2Style.Font.Italic = true;

Thanks,
G

Hi Giancarlo,
Thanks for your inquiry.
Could you also attach your template document here for testing? We will look into this further for you.
Thanks,

Attached. btw, you’re white list of file extensions includes dot but not dotx so I had to zip it up.

Hello
Thank you for additional information. As I can see there is no any “Organization Name” style inside your document. Please see the following code:

Document _document = new Document("C:\\Temp\\QuickPrintTemplate.dotx");
foreach(Style style in _document.Styles)
{
    Console.WriteLine(style.Name);
}

But you can create and apply this style using the following code:

Document doc = new Document("C:\\Temp\\QuickPrintTemplate.dotx");
DocumentBuilder builder = new DocumentBuilder(doc);
Style h2Style = doc.Styles.Add(StyleType.Paragraph, "Organization Name");
h2Style.Font.Bold = true;
h2Style.Font.Size = 20;
h2Style.Font.Color = Color.Black;
h2Style.Font.Italic = true;
h2Style.ParagraphFormat.SpaceBefore = 10;
h2Style.ParagraphFormat.SpaceAfter = 10;
builder.ParagraphFormat.Style = h2Style;
builder.Writeln("OrganizationName");
doc.Save("C:\\Temp\\out.docx");

Best regards,

The code I wrote in my post is an example, I’m aware it doesn’t have Organization Name as a style, but it does Organization Header which is what I was calling in my code. In any case, there may be something wrong with the document because I created a different DOTX and it is working fine.

Hi Giancarlo,
Thank you for additional information. But I also does not see a “Organization Header” style in your template. Could you please create a simple application that will allow us to reproduce the problem? We will check the issue one more time and provide you more information.
Best regards,