Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MS Word Automation - Combining word documents

MS Word Automation - Combining word documents

Scheduled Pinned Locked Moved C#
helpcsharpdatabasetestingtools
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venadder
    wrote on last edited by
    #1

    Hi, I am working on a MS Word Automation project using VS2008 and Office 2003 in c# language. I have a One Page Word template which have bookmarks in table cells. These bookmarks are placeholders where specific information is put in from database using c#. I generate say 10 documents based on the template and save them as seperate file. What I would like is to have a 10 page single document. I can use selection.insertfile to create this document. When I do this, all the formatting goes bersek. Basically what i do is:

    Word.Application app = new Word.Application( );
    Word._Document wordDocument = app.Documents.Add(

                                    ref originalTemplate
    
                                  , ref oMissing
    
                                  , ref oMissing
    
                                  , ref oMissing);
    
    
      Word.Selection selection = app.Selection;
    
      
    
      int documentCount = MyGeneratedFiles.Length;
      int breakStop = 0;
    
      foreach (string file in MyGeneratedFiles)
    
      {
    
        breakStop++;
    
        // Insert the files to our template
    
        selection.InsertFile(
    
                                file
    
                                , ref oMissing
    
                                , ref oMissing
                                , ref oMissing
    
                                , ref oMissing);
    
    
    
    
    
    
    
        try
    
        {
    
          if (breakStop != documentCount)
    
            selection.InsertBreak(ref pageBreak);
    
        }
    
        catch (Exception ex) { }
    
      }
    
      wordDocument = null;
    
      app.Visible = true;
    

    This works as far as combining all documents is concerned. But the formattign goes crazy and there are no clearly defined pageBreaks. Is there a better way to combine multiple one page documents into one multi-page single document? I have been stuck on this for a while, any help will be much appreciated. Thank you

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups