Scenario
I have one master doc file and I have to copy master doc file styles and need to add in another ten documents(documents has content in it).
Code
- Code: Select all
Document doc = new Document();
doc.LoadFromFile(filepathFrom);
Document newWord = new Document();
newWord.LoadFromFile(filepats);
foreach (IStyle style in doc.Styles)
{
newWord.Styles.Add(style);
}
newWord.Sections.Add(doc.Sections[0].Clone());
var GetFiles = Path.GetFileName(filepats);
var Output = string.Format(@"C:\****\Doc\{0}", GetFiles);
newWord.SaveToFile(Output);
tried online example but does not work
- Code: Select all
Document doc = new Document();
doc.LoadFromFile("theme.docx");
Document newWord = new Document();
doc.CloneDefaultStyleTo(newWord);
doc.CloneThemesTo(newWord);
doc.CloneCompatibilityTo(newWord);
newWord.Sections.Add(doc.Sections[0].Clone());
newWord.SaveToFile("result.docx", FileFormat.Docx);
Note: I just only wants to copy the styles of master doc to another doc.
Cheers,
Jay