Click here to Skip to main content
15,560,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have created multiple diffrent docx file using open xml and when i am merging all formatting of every docx reset and merged with first doc formatting. Please help me when my docx file will merge then formatting and design should be remain of every pages.
My sniped code below:

using (WordprocessingDocument myDoc = WordprocessingDocument.Create(resultDoc, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true))
            {
                MainDocumentPart mainPart = myDoc.AddMainDocumentPart();
                new DocumentFormat.OpenXml.Wordprocessing.Document(new Body()).Save(mainPart);
                mainPart.Document.Body = new Body(new Paragraph());

                // Paragraph para = new Paragraph(new Run(new Break() { Type = BreakValues.Page }));
                // mainPart.Document.Body.InsertAfter(para, mainPart.Document.Body.LastChild);

                string altChunkId = "AltChunkId" + count;
                AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(
                    AlternativeFormatImportPartType.WordprocessingML, altChunkId);
                using (FileStream fileStream = System.IO.File.Open(@"cover.docx", FileMode.Open))
                {
                    chunk.FeedData(fileStream);
                }

                chunk.FeedData(coverDoc);
                AltChunk altChunk = new AltChunk();
                altChunk.Id = altChunkId;
                mainPart.Document.Body.InsertAfter(altChunk, mainPart.Document.Body.Elements<Paragraph>().Last());
                mainPart.Document.Save();
                myDoc.Close();
                count = count + 1;
            }


What I have tried:

Open Xml Sdk, Word Docx file Merging
Posted
Updated 8-Nov-20 21:40pm
Comments
Gerry Schmitz 31-Jul-20 13:23pm    
What do you think "merge" means? Contrast that with "concatenating".
Pramod_Kumar1 1-Aug-20 3:34am    
I have multiple docx file with diffrent formatting and design so i am combing all files one.I am using open xml, please suggest better solution, formatting and design should be remain of each files.
Member 15876543 27-Dec-22 2:03am    
Pramod did you get a solution for this?
If so can you share those details

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