Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Guys,

I have the following problem.

I have two documents

doc 1:

-----------------------
header
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------
Footer
-----------------------


Doc2
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------

What I need is:
-----------------------
header
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------
Footer
-----------------------
page break
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------

I have all the code to return to me either _documents or the actual saved files.

All I need is some code to merge them to give me the desired effect.

If you have a c# code snippet or some links I would truly appreciate it.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Nov-11 13:47pm    
Why this is a problem? Any particular difficulty?
--SA
Member 8334897 22-Nov-11 0:49am    
Hey,

Ye, ive been trying all sorts of code. Every time when I do get them to merge I have several problems like formatting problems, the one problem I had with formatting was that when I merged the documents, the header/footer repeats onto the second document.

Any ideas on how to solve this?

Something along the lines of:

C#
pageSetup.HeaderDistance = 20;

  builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

  builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;



This may not be perfect. Adjust as needed.

--Vlad781
 
Share this answer
 
Hi,

you can accomplish this task easily with this C# / VB.NET Word library that doesn't use C# Word Interop.

Here is a sample C# code:
C#
// Use the component in free mode.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

// Create document instance that will contain all concatenated input documents.
var finalDocument = new DocumentModel();

// For each input document.
foreach (string filePath in filePaths)
{
	// Load an input document.
	var document = DocumentModel.Load(filePath, LoadOptions.DocxDefault);

	// Import and add every input document section to the final document.
	foreach (var section in document.Sections)
		finalDocument.Sections.Add(finalDocument.Import(section, true));
}

// Save final document to a file.
finalDocument.Save("FinalDocument.docx", SaveOptions.DocxDefault);
 
Share this answer
 
 
Share this answer
 
Comments
RaviRanjanKr 27-Nov-11 14:50pm    
My 5+
 
Share this answer
 
Comments
RaviRanjanKr 27-Nov-11 14:50pm    
My 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900