Word Formats Setting when Merge Word Files

Posted by Eva2012 under C# on 2/27/2013 | Points: 10 | Views : 1169 | Status : [Member] | Replies : 1
Word merge feature enables developers to quickly merge word files into one. But sometimes, we find that the position of text in the merged file displays incorrect. Also the file format of the first word page influences the second, the third.etc. I have encountered the question for a long time, finally solved this, I share it here, hope can give you some insights Here I give you an example, suppose there are two word file, I want to merge them into one. I set the page border of the first file surround the header and footer, but the second not. When I merge them into one, the second word page in the merge word file also has borders surround the header and footer, in such a case,we need to add another two lines after the code. The whole code can be as below:
string fileName = @"..\..\File1.doc";
string fileMerge = @"..\..\File2.doc";
if ((!string.IsNullOrEmpty(fileName)) && (!string.IsNullOrEmpty(fileMerge)))
Spire.Doc.Document document = new Spire.Doc.Document();
document.LoadFromFile(fileName, FileFormat.Doc);
Spire.Doc.Document documentMerge = new Spire.Doc.Document();
documentMerge.LoadFromFile(fileMerge, FileFormat.Doc);
foreach (Spire.Doc.Section sec in documentMerge.Sections)
{ document.Sections.Add(sec.Clone()); }
//added two lines
document.Sections[0].PageSetup.PageBorderIncludeFooter = false;
document.Sections[0].PageSetup.PageBorderIncludeHeader = false;
document.SaveToFile("MergedDocument.doc", FileFormat.Doc);


Posted by: Poisy on: 8/27/2013 [Member] Starter | Points: 25

thanks for sharing. I use a PDF merger driver found on the internet . Install it and it becomes a selectable merger option.Then you can merge PDFs into one in any program at all, including Adobe Acrobat . Just open the PDFs, select merge, and choice the form you want, the task will be finished in several seconds. if you haven't found a good choice , you can have a try. best wishes.http://www.rasteredge.com/how-to/vb-net-imaging/word-merge/

Eva2012, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response