locked
How to add multiple documents into a single word document RRS feed

  • Question

  • User-1526529263 posted

    I have written the following code:

     Dim cmdString As String = "Select x from abc where s='Y'"

     

    Try

    With oWord

    conn = New OracleConnection("Persist Security Info=False;User ID=abc;password=abc;Max Pool Size=5;Min Pool Size=1;Connection Lifetime=2000;Data Source=Mabc")

    cmd = New OracleCommand(cmdString, conn)

    cmd.CommandType = CommandType.Text

    da =
    New OracleDataAdapter

    da.SelectCommand = cmd

    dt =
    New DataTable()

    conn.Open()

    da.Fill(dt)

    dq = dt.Rows

    Dim rng As Word.Range

    rng = oDoc.Range(0, 0)

    For i = 0 To (dq.Count - 1)strPath = dq(i)("x").ToString()

    oDoc.Content.InsertFile(strPath)

    'Go to end of Document

    oDoc.GoTo(Word.WdGoToItem.wdGoToPage, Word.WdGoToDirection.wdGoToLast)

    Next

    My doubt is:

     This x column in the database is having multiple rows, each row containing particular path for the particular document. But when i run this code documents are getting overlapped.

    I want that final word document should contain the documents for all the rows.

    Thanks

    Tuesday, September 9, 2008 9:05 AM

All replies

  • User21295764 posted

    i had a similar problem.

     

    my sollution was to first create seperate documents. Then create a new document and insert the previously created documents:

     

      'create merge document
                Dim mergeDoc As Word.Document = Nothing
                mergeDoc = Me.wordApp.Documents.Add(Template:=templatePath)
    
                For Each section As String In sectionFiles
                    mergeDoc.Bookmarks("\EndOfDoc").Range.InsertBreak(Type:=Word.WdBreakType.wdSectionBreakNextPage)
                    wordApp.Selection.EndKey(Unit:=Word.WdUnits.wdStory)
                    wordApp.Selection.InsertFile(FileName:=section, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False)
                Next

     

     

    Friday, May 4, 2012 9:29 AM