wordpress hit counter
Re: two or more than two word docx (in 2007) merge into single docx at runtime. - .Net - Development Tools - OpenXML Developer

Re: two or more than two word docx (in 2007) merge into single docx at runtime.

Development Tools

Discussions about working with Open XML using a wide range of development tools

two or more than two word docx (in 2007) merge into single docx at runtime.

  • rated by 0 users
  • This post has 4 Replies |
  • 1 Follower
  • Hi ,

    I have developed vb.net application to create docx (using Openxml ) now I want to merge these docx documents into single document runtime using .net code , please help me to solve this problem.

    Thank you in advance

    Umesh.

     

     

       

  • Hi Umesh

    I've just given this code a go which works:
    public static void MergeDocuments(string sourceFile, string destinationFile)
    {
      using (WordprocessingDocument myDoc = WordprocessingDocument.Open(destinationFile, true))
      {
        string altChunkId = "AltChunkId1";
        MainDocumentPart mainPart = myDoc.MainDocumentPart;
        AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);
        using (FileStream fileStream = File.Open(sourceFile, FileMode.Open))
        {
            chunk.FeedData(fileStream);
        }
        AltChunk altChunk = new AltChunk();
        altChunk.Id = altChunkId;
        mainPart.Document.Body.InsertAfter(altChunk, mainPart.Document.Body.Elements<Paragraph>().Last());
        mainPart.Document.Save();
      }
    }

    This is quite well covered here -> http://blogs.msdn.com/b/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx
  • Hi,

    I am trying to merge word documents in sharepoint document library. Some pages in the docs are in portrait and some in landscape. after merging documents all the pages in the documents r displayed in portrait mode. how can i retain page orientation programmatically ?

    Plz let me know how to insert section properties after each page or each document ?

    here is  my code

    Appreciate your help..

                foreach (SPFile item in listitem.Folder.Files)

                {

                  //  SPFile inputFile = item.File;

                    SPFile inputFile = item;

     

                    string altChunkId = "AltChunkId" + id;

                    id++;

                    byte[] byteArray = inputFile.OpenBinary();

     

                    AlternativeFormatImportPart chunk = outputDoc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML,

                        altChunkId);

     

                    using (MemoryStream mem = new MemoryStream())

                    {

                        mem.Write(byteArray, 0, (int)byteArray.Length);

                        mem.Seek(0, SeekOrigin.Begin);

                        chunk.FeedData(mem);

                    }

     

                    AltChunk altChunk = new AltChunk();

                    altChunk.Id = altChunkId;

     

                    outputDoc.MainDocumentPart.Document.Body.InsertAfter(altChunk,

                        outputDoc.MainDocumentPart.Document.Body.Elements<Paragraph>().Last());

                    outputDoc.MainDocumentPart.Document.Save();

                }

     

                outputDoc.Close();

     

                memOut.Seek(0, SeekOrigin.Begin);

     

                ClientContext clientContext = new ClientContext(SPContext.Current.Site.Url);

                ClientOM.File.SaveBinaryDirect(clientContext, outputPath, memOut, true);

     

                // Conversion

     


     

  • This might give you an idea on how to do it:

    http://www.wordbanter.com/showthread.php?t=142774
  • Thanks
Page 1 of 1 (5 items)