Mass update of styles not possible after document is generated

Also attaching the document for above code-
FramsiktExport (14).docx (16.2 KB)

Thank you.
Regards,
Kamaraju.

@kamaraju2407 Here you have the same problem with inheritance. Formatting from table style is not applied to the element if explicit formatting is set. In your case the first table has explicit border formatting, so it overrides the borders specified in the table style. You can clear borders to get the borders formatting from table style applied:

Document doc = new Document(@"C:\Temp\in.docx");

TableStyle tableStyle = (TableStyle)doc.Styles.Add(StyleType.Table, "test");
tableStyle.BaseStyleName = "Table Normal";
tableStyle.Font.Size = 5;
tableStyle.Borders.Color = Color.Red;
tableStyle.Borders.LineStyle = LineStyle.DotDash;

NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
foreach (Table t in tables)
{
    t.Style = tableStyle;

    t.ClearBorders();

    NodeCollection runs = t.GetChildNodes(NodeType.Run, true);
    foreach (Run r in runs)
        r.Font.Size = 8;
}

doc.Save(@"C:\Temp\out.docx");

Thank you Alexey, I got it now.
But in the below code, i deleted the explicit style and add the table style, but this also dont work.

FramsiktExport (15).docx (15.8 KB)

Thank you.
Regards,
Kamaraju.

Hi Alexey,

Did you get a chance to look at my previous query?
Please tell me where i went wrong.

Thank you.
Regards,
Kamaraju.

@kamaraju2407 Explicit formatting and style are different things. In your code you simply remove style, your code does not remove explicit formatting applied directly to nodes. In your case you would like the font size to be set through the table style, in this case Run nodes in your table should not have the font size set explicitly. I have already mentioned this in one of my previous answers. To remove explicit font formatting you can use Font.ClearFromatting() method, but this will remove all explicit font formatting.

Hi Alexey,

Can you please help me with my query?
is there any way to find which table/row/cell has explicit formatting applied and which has not?

Thank you.
Regards,
Kamaraju.

@kamaraju2407 Unfortunately, there is no way to detect this using public Aspose.Words API. Aspose.Words provides access to the node’s attributes using properties, which returns default or inherited value if the attribute is not set explicitly.

Thank you Alexey for your assistance.

Thank you.
Regards,
Kamaraju.

1 Like