| |
|
HomeNewsExamplesDemoDownloadsFAQDocumentationMailing ListsLicense
|
|
7:39 pm GMT
GeSHi - Generic Syntax Highlighter
Latest News
News Archive
|
Random Screenshot
Demonstration
Runtime Example
Sub MergeDocumentsInDirectory()
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
' force a trailing backslash. This is okay because using URL notation
If Right(DestDirectory,1) <> "/" Then
DestDirectory = DestDirectory & "/"
End If
oDeskTop = CreateUnoService("com.sun.star.frame.Desktop")
' 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
|
|