traverse document Darragh Sherwin Tom Schindl How can I copy things from on to another document # Class to copy 30 lines of text # This will break table up, if there is a table # in the 30 lines selected by the viewCursor class Copier( unohelper.Base, XJobExecutor ): def __init__( self, ctx ): self.ctx = ctx # For a desktop example see {%internal ../Office/Office.FetchingServicesFromDesktop.snip} deskDict = getDesktopDict( ctx ) self.splitDocument( deskDict ) # Splits the document def splitDocument( self, deskDict ): viewCursor = deskDict['viewcursor'] text = deskDict['document'].Text controller = deskDict['controller'] textCursor = text.createTextCursor() textCursor.gotoRange( text.getStart(), False ) viewCursor.gotoRange( deskDict['document'].Text.getStart(), False ) deskDict['viewcursor'] = viewCursor endRange = text.getEnd() viewCursor.gotoStart( False ) while ( text.compareRegionEnds( viewCursor, endRange ) > 0 ): # The viewCursor is selecting the 30 lines viewCursor.goDown( 30, True ) controller.select( controller.getSelection() ) # This executes the copy function # How to use dispatch see {%internal ../Office/Office.UsingDispatchAPI.snip} executeSlot( self.ctx, controller, ".uno:Copy") # How to create a document see {%internal ../Office/Office.UsingDispatchAPI.snip} docDict = createNewDocument( deskDict ) self.pasteToNewDoc( docDict ) controller.getFrame().getComponentWindow().setFocus( ) textCursor.gotoRange( viewCursor.getEnd() , False) viewCursor.gotoRange( textCursor, False ) # Pastes the system clipboard into the document def pasteToNewDoc( self, deskDict ): document = deskDict['document'] # How to use dispatch see {%internal ../Office/Office.UsingDispatchAPI.snip} executeSlot( self.ctx, deskDict['controller'], ".uno:Paste") if __name__=="__main__": # For a connection example see {%internal ../Office/Office.ConnectViaPipe.snip} remoteContext = connect() try: job = Copier( remoteContext ) except Exception, e: print "\n\n" import traceback traceback.print_exc()