Replacing document styles with that from another document/template

Hi,

Is it possible to replace all of the styles (including built-in) from a document A with those from a different document or template B?
So if document B uses Arial as a Normal style font then document A’s Normal style would also use Arial.

Thank you,

Hi John,

Thanks for your inquiry. Please use StyleCollection.AddCopy method to achieve your requirements. This method copies linked style but doesn’t copy base styles.

Following code snippet demonstrates how to copy a style within the same document.

// The AddCopy method creates a copy of the specified style and automatically generates a new name for the style, such as "Heading 1_0".
Style newStyle = doc.Styles.AddCopy(doc.Styles["Heading 1"]);
// You can change the new style name if required as the Style.Name property is read-write.
newStyle.Name = "My Heading 1";

Following code snippet demonstrates how to copy a style from one document to another and override an existing style in the destination document.

// This is the style in the source document to copy to the destination document.
Style srcStyle = srcDoc.Styles[StyleIdentifier.Heading1];
// Change the font of the heading style to red.
srcStyle.Font.Color = Color.Red;
// The AddCopy method can be used to copy a style to a different document.
Style newStyle = dstDoc.Styles.AddCopy(srcStyle);
// The name of the new style can be changed to the name of any existing style. Doing this will override the existing style.
newStyle.Name = "Heading 1";