There is a basic macro in openoffice that does this, the code uses the methodology of extracting the document and appending to the other document. I know they use OOo on the background, but shoud give you some notes about the logic of the way to do this. Something similar to a bash:
cat doc1 doc2 > newdoc. There is also a ooomerge.py ( http://www.openoffice.org/udk/python/samples/oomerge.py) script that generates a new document from 2 documents, the code uses from com.sun.star.style.BreakType import PAGE_BEFORE, PAGE_AFTER. The function use the following lines to cursor.gotoEnd(False) cursor.BreakType = PAGE_BEFORE cursor.insertDocumentFromURL(fileUrl, ()) Merge all documents: 'Modified by: Andrew Pitonyak Sub MergeDocumentsInDirectory() ' On Error Resume Next Dim DestDirectory As String Dim FileName As String Dim SrcFile As String, DstFile As String Dim oDesktop, oDoc, oCursor, oText Dim argsInsert() Dim args() 'Remove the following comments to do things hidden 'Dim args(0) As New com.sun.star.beans.PropertyValue 'args(0).name="Hidden" 'args(0).value=true 'Which desitnation directory? DestDirectory=Trim(GetFolderName()) If DestDirectory = "" Then MsgBox "No directory selected, exiting",16,"Merging Documents" Exit Sub End If REM Force a trailing backslash. REM This is okay because using URL notation If Right(DestDirectory,1) <> "/" Then DestDirectory=DestDirectory & "/" End If oDeskTop=CreateUnoService("com.sun.star.frame.Desktop") REM Read the first file! FileName=Dir(DestDirectory) DstFile = ConvertToURL(DestDirectory & "ResultatFusion.sxw") Do While FileName <> "" If lcase(right(FileName,3))="sxw" Then SrcFile = ConvertToURL(DestDirectory & FileName) If IsNull(oDoc) OR IsEmpty(oDoc) Then FileCopy( SrcFile, DstFile ) oDoc=oDeskTop.Loadcomponentfromurl(DstFile, _ "_blank", 0, Args()) oText = oDoc.getText oCursor = oText.createTextCursor() Else oCursor.gotoEnd(false) oCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE oCursor.insertDocumentFromUrl(SrcFile, argsInsert()) End If End If FileName=dir() Loop If IsNull(oDoc) OR IsEmpty(oDoc) Then MsgBox "No documents merged!",16,"Merging Documents" Exit Sub End If 'Save the document Dim args2() oDoc.StoreAsURL(DestDirectory & "ResultatFusion.sxw",args2()) If HasUnoInterfaces(oDoc, "com.sun.star.util.XCloseable") Then oDoc.close(true) Else oDoc.dispose() End If 'Reload the document! oDoc=oDeskTop.Loadcomponentfromurl(DstFile,"_blank",0,Args2()) End Sub On Fri, Mar 1, 2013 at 7:42 AM, Rob Weir <[email protected]> wrote: > On Thu, Feb 28, 2013 at 2:31 PM, Shemeer AT <[email protected]> wrote: > > > > > > > > Hello, > > > > > > > > I am new to this project. > > > > I would like to add one document in another document. > > > > What do you mean? > > 1 Add the contents of one document to another document, i.e., merge > two documents? > > or > > 2) Insert one document as an embedding (a subdocument) into a second > document? > > -Rob > > > How I can achieve this using java. > > > > Please help me. > -- Alexandro Colorado Apache OpenOffice Contributor http://es.openoffice.org
