- Code: Select all
Document doc1 = new Document("E:\\Test01.docx");
Document doc2 = new Document("E:\\Test02.docx");
foreach (Section sec in doc2.Sections)
{
doc1.Sections.Add(sec.Clone());
}
doc2.Dispose();
foreach (Section sec in doc1.Sections)
{
foreach (Paragraph para in sec.Paragraphs)
{
string[] split = para.StyleName.Split('_');
if (split.Length >= 2)
{
para.ApplyStyle(split[0]);
}
}
}
doc1.IsUpdateFields = true;
doc1.SaveToFile("E:\\Test.docx");
doc1.Dispose();