 | OO-Snippets: Copy components to new documentCommons| Keywords | traverse document |
|---|
| Language | Python |
|---|
| Application | Writer |
|---|
| Authors | Darragh Sherwin (initial)
Tom Schindl (initial)
|
|---|
| Supported Versions | |
|---|
| Supported OS | All |
|---|
| Question | How can I copy things from on to another document
|
|---|
| Answer | |
|---|
class Copier( unohelper.Base, XJobExecutor ):
def __init__( self, ctx ):
self.ctx = ctx
deskDict = getDesktopDict( ctx )
self.splitDocument( deskDict )
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 ):
viewCursor.goDown( 30, True )
controller.select( controller.getSelection() )
executeSlot( self.ctx, controller, ".uno:Copy")
docDict = createNewDocument( deskDict )
self.pasteToNewDoc( docDict )
controller.getFrame().getComponentWindow().setFocus( )
textCursor.gotoRange( viewCursor.getEnd() , False)
viewCursor.gotoRange( textCursor, False )
def pasteToNewDoc( self, deskDict ):
document = deskDict['document']
executeSlot( self.ctx, deskDict['controller'], ".uno:Paste")
if __name__=="__main__":
remoteContext = connect()
try:
job = Copier( remoteContext )
except Exception, e:
print "\n\n"
import traceback
traceback.print_exc()
|
|