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. concatenate the word document, it's possible?

concatenate the word document, it's possible?

Scheduled Pinned Locked Moved C#
comquestion
8 Posts 5 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.
  • A Offline
    A Offline
    abbd
    wrote on last edited by
    #1

    How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :

                String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                string nb = tbStr2\[0\];
                Object oMissing = System.Reflection.Missing.Value;
                Object oTrue = true;
                Object oFalse = false;
                Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                oWord.Visible = true;
                oWord.Visible = false;
                Object oTemplatePath = modelee;
                oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
    
                foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                {if (range.Text.Trim().Contains("$"))
                    {   int pos = range.Text.Trim().IndexOf("$");
                        string str = range.Text.Trim().Replace("$", "");
                        range.Text = str;} }
                        
                foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                {if (range.Text.Trim().Contains("$$"))
                    {   int pos = range.Text.Trim().IndexOf("$$");
                        string str = range.Text.Trim().Replace("$$", "");
                        range.Text = str;} }
                
                Object oSaveAsFile ="./1.doc";
                oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);
                oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
    
    L A D R 4 Replies Last reply
    0
    • A abbd

      How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :

                  String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                  string nb = tbStr2\[0\];
                  Object oMissing = System.Reflection.Missing.Value;
                  Object oTrue = true;
                  Object oFalse = false;
                  Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                  Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                  oWord.Visible = true;
                  oWord.Visible = false;
                  Object oTemplatePath = modelee;
                  oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                  bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
      
                  foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                  {if (range.Text.Trim().Contains("$"))
                      {   int pos = range.Text.Trim().IndexOf("$");
                          string str = range.Text.Trim().Replace("$", "");
                          range.Text = str;} }
                          
                  foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                  {if (range.Text.Trim().Contains("$$"))
                      {   int pos = range.Text.Trim().IndexOf("$$");
                          string str = range.Text.Trim().Replace("$$", "");
                          range.Text = str;} }
                  
                  Object oSaveAsFile ="./1.doc";
                  oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                  ref oMissing, ref oMissing);
                  oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                  oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yes, should be possible. What are you using to "read" the document?

      Bastard Programmer from Hell :suss:

      1 Reply Last reply
      0
      • A abbd

        How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :

                    String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                    string nb = tbStr2\[0\];
                    Object oMissing = System.Reflection.Missing.Value;
                    Object oTrue = true;
                    Object oFalse = false;
                    Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                    Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                    oWord.Visible = true;
                    oWord.Visible = false;
                    Object oTemplatePath = modelee;
                    oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                    bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
        
                    foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                    {if (range.Text.Trim().Contains("$"))
                        {   int pos = range.Text.Trim().IndexOf("$");
                            string str = range.Text.Trim().Replace("$", "");
                            range.Text = str;} }
                            
                    foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                    {if (range.Text.Trim().Contains("$$"))
                        {   int pos = range.Text.Trim().IndexOf("$$");
                            string str = range.Text.Trim().Replace("$$", "");
                            range.Text = str;} }
                    
                    Object oSaveAsFile ="./1.doc";
                    oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing);
                    oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                    oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
        
        A Offline
        A Offline
        Alan N
        wrote on last edited by
        #3

        A tip you will often see is to record a macro for the operation you want to perform. In your case just find out what code is generated for the Insert File operation. In Word 2002 the macro code is

        Sub Macro1()
        Selection.InsertFile FileName:="xxxxx.doc", Range:="", ConfirmConversions:= False, Link:=False, Attachment:=False
        End Sub

        From the MS Word Visual Basic reference we can get the InsertFile method signature and remove the named arguments to give the conventional method call

        Selection.InsertFile("xxxx.doc", "", False, False, False)

        which can be easily translated into C#. Alan.

        1 Reply Last reply
        0
        • A abbd

          How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :

                      String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                      string nb = tbStr2\[0\];
                      Object oMissing = System.Reflection.Missing.Value;
                      Object oTrue = true;
                      Object oFalse = false;
                      Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                      Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                      oWord.Visible = true;
                      oWord.Visible = false;
                      Object oTemplatePath = modelee;
                      oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                      bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
          
                      foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                      {if (range.Text.Trim().Contains("$"))
                          {   int pos = range.Text.Trim().IndexOf("$");
                              string str = range.Text.Trim().Replace("$", "");
                              range.Text = str;} }
                              
                      foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                      {if (range.Text.Trim().Contains("$$"))
                          {   int pos = range.Text.Trim().IndexOf("$$");
                              string str = range.Text.Trim().Replace("$$", "");
                              range.Text = str;} }
                      
                      Object oSaveAsFile ="./1.doc";
                      oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                      ref oMissing, ref oMissing);
                      oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                      oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
          
          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Who in their right mind would want to open a 1,000 page document in Word?? That'll take, what, a few hours to do?

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          A 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Who in their right mind would want to open a 1,000 page document in Word?? That'll take, what, a few hours to do?

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            A Offline
            A Offline
            Alan N
            wrote on last edited by
            #5

            No, only a few seconds if not bloated with a shed load of pictures. E.g. the C# Specification v3.0 is 519 pages and takes about 3 seconds to open over here in the UK. Alan.

            D 1 Reply Last reply
            0
            • A Alan N

              No, only a few seconds if not bloated with a shed load of pictures. E.g. the C# Specification v3.0 is 519 pages and takes about 3 seconds to open over here in the UK. Alan.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Damn, must be my machine.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              1 Reply Last reply
              0
              • A abbd

                How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much. i use this to crate one document :

                            String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                            string nb = tbStr2\[0\];
                            Object oMissing = System.Reflection.Missing.Value;
                            Object oTrue = true;
                            Object oFalse = false;
                            Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                            Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                            oWord.Visible = true;
                            oWord.Visible = false;
                            Object oTemplatePath = modelee;
                            oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                            bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
                
                            foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                            {if (range.Text.Trim().Contains("$"))
                                {   int pos = range.Text.Trim().IndexOf("$");
                                    string str = range.Text.Trim().Replace("$", "");
                                    range.Text = str;} }
                                    
                            foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                            {if (range.Text.Trim().Contains("$$"))
                                {   int pos = range.Text.Trim().IndexOf("$$");
                                    string str = range.Text.Trim().Replace("$$", "");
                                    range.Text = str;} }
                            
                            Object oSaveAsFile ="./1.doc";
                            oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing);
                            oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                            oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                
                R Offline
                R Offline
                RaviRanjanKr
                wrote on last edited by
                #7

                Try Merge Multiple Microsoft Word Documents in C#[^] I hope it will might help you.

                A 1 Reply Last reply
                0
                • R RaviRanjanKr

                  Try Merge Multiple Microsoft Word Documents in C#[^] I hope it will might help you.

                  A Offline
                  A Offline
                  abbd
                  wrote on last edited by
                  #8

                  Thank you verry mutch for your answer, so i need to merge the word file in the memory, because i don't want to generate all 1000 files. please help me.

                  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