I am inserting one document into another.
Destination document has only few paragraphs. Source has 2 section breaks - Continuous.
When I insert source document into destination, second section break will become Next Page that is not valid. I have tried also with case where source document has more than 2 section breaks of type Continuous. Last section break will be always switched to Next Page. All others remain as they were before. In case when last one section break is of type Next Page, than everything will be OK Code snippet - InsertFile method
One more issue/question. Destination document has one column text. Source document starts with 2 columns text and has after it one section break Continuous. By default after insertion first section in destination document becomes 2 columns text that I do not expect. Looks like formatting from source document was taken. I can bridge this by setting column text like : SetColumnText method.
public static void InsertFile()
{
Document destDoc = new Document(“FirstSection.docx”);
Document sourceDoc = new Document(@“SecondSection.docx”);
DocumentBuilder builder = new DocumentBuilder(destDoc);
builder.MoveToDocumentEnd();
builder.InsertDocument(sourceDoc, ImportFormatMode.KeepSourceFormatting);
string documentName = Guid.NewGuid() + “.docx”;
destDoc.Save(documentName, SaveFormat.Docx);
}
public static void SetColumnText (Document sourceDoc, Document destDoc)
{ sourceDoc.FirstSection.PageSetup.TextColumns.SetCount(destDoc.LastSection.PageSetup.TextColumns.Count);
sourceDoc.FirstSection.PageSetup.TextColumns.EvenlySpaced = destDoc.LastSection.PageSetup.TextColumns.EvenlySpaced;
sourceDoc.FirstSection.PageSetup.TextColumns.LineBetween = destDoc.LastSection.PageSetup.TextColumns.LineBetween;
sourceDoc.FirstSection.PageSetup.TextColumns.Spacing = destDoc.LastSection.PageSetup.TextColumns.Spacing;
}