REM ***** BASIC ***** REM Code examples for LXF83 Sub Main setHeaderAndFooter End Sub Sub showMessage msgbox "OK" End Sub Sub setUpMenu sMenuBar = "private:resource/menubar/menubar" sMyPopupMenuCmdId = ".uno:PickList" oModuleCfgMgrSupplier = _ createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier") oModuleCfgMgr = _ oModuleCfgMgrSupplier.getUIConfigurationManager _ ( "com.sun.star.text.TextDocument" ) oMenuBarSettings = oModuleCfgMgr.getSettings( sMenuBar, true ) oPopupMenu = oMenuBarSettings.getByIndex(0) oPopupMenuContainer = oPopupMenu(2).Value oMenuItem = CreateMenuItem( "macro:///Standard.Module2.Test()", "Standard.Module2.Test" ) oPopupMenuContainer.insertByIndex( 0,oMenuItem) oMenuBarSettings.insertByIndex( nCount, oPopupMenu ) oModuleCfgMgr.replaceSettings( sMenuBar, oMenuBarSettings ) End Sub Function CreateMenuItem( Command as String, Label as String ) as Variant Dim aMenuItem(2) as new com.sun.star.beans.PropertyValue aMenuItem(0).Name = "CommandURL" aMenuItem(0).Value = Command aMenuItem(1).Name = "Label" aMenuItem(1).Value = Label aMenuItem(2).Name = "Type" aMenuItem(2).Value = 0 CreateMenuItem = aMenuItem() End Function 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 Sub GetFolderName oFolderDialog = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker") iAccept = oFolderDialog.Execute() End SUb Sub setHeaderAndFooter oDoc = ThisComponent oStyles = oDoc.getStyleFamilies().getByName( "PageStyles" ) oPStyle = oStyles.getByName( "Default" ) ' Get page number and page count objects. oPageNumber = oDoc.createInstance( "com.sun.star.text.TextField.PageNumber" ) oPageCount = oDoc.createInstance( "com.sun.star.text.TextField.PageCount" ) oDateTime = oDoc.createInstance( "com.sun.star.text.TextField.DateTime" ) ' Edit header oHeader = oPStyle.RightPageHeaderContent oHeader.getLeftText().setString( "" ) oHeader.getCenterText().setString( "ABC Company, Inc." ) oCursor = oHeader.getRightText().createTextCursor() oHeader.getRightText().insertTextContent( oCursor, oDateTime, True ) oPStyle.RightPageHeaderContent = oHeader ' Edit footer oFooter = oPStyle.RightPageFooterContent oFooter.getLeftText().setString( "Monthly Report" ) oFooter.getCenterText().setString( "" ) oFooter.getRightText().setString( "Page " ) oCursor = oFooter.getRightText().createTextCursor() oCursor.gotoEnd( False ) oFooter.getRightText().insertTextContent( oCursor, oPageNumber, True ) oCursor.gotoEnd( False ) oCursor.setString( " of " ) oCursor.gotoEnd( False ) oFooter.getRightText().insertTextContent( oCursor, oPageCount, True ) oPStyle.RightPageFooterContent = oFooter End Sub Sub InsertATOC REM Author: Andrew Pitonyak Dim oCurs 'Used to insert the text content. Dim oIndexes 'All of the existing indexes Dim oIndex 'The TOC if it exists and a new one if not Dim i As Integer 'Find an existing TOC Dim bIndexFound As Boolean 'Flag to track if the TOC was found REM First, find an existing TOC if it exists. If so, REM then this will simply be updated. oIndexes = ThisComponent.getDocumentIndexes() bIndexFound = False For i = 0 To oIndexes.getCount() - 1 oIndex = oIndexes.getByIndex(i) If oIndex.supportsService("com.sun.star.text.ContentIndex") Then bIndexFound = True Exit For End If Next If Not bIndexFound Then Print "I did not find an existing content index" REM Perhaps you should create and insert a new one! REM Notice that this MUST be created by the document that will contain REM the index. oIndex = ThisComponent.createInstance("com.sun.star.text.ContentIndex") REM On my system, these are the default values REM How do you want to create the index? REM CreateFromChapter = False REM CreateFromLevelParagraphStyles = False REM CreateFromMarks = True REM CreateFromOutline = False oIndex.CreateFromOutline = True REM You can set all sorts of other things such as the REM Title or Level oCurs = ThisComponent.getText().createTextCursor() oCurs.gotoStart(False) ThisComponent.getText().insertTextContent(oCurs, oIndex, False) End If REM Even the newly inserted index is not updated until right HERE! oIndex.update() End Sub