Bei näherem Hinsehen kann die Methode CopyRange hier nicht erfolgreich sein. CopyRange ist eine Methode des Interfaces XCellRangeMovement und ist in der API unter com.sun.star.
sheet zu finden. Da heißt es dann auch gleich "copies a cell range to another position
in the document. .
Die Range funktioniert über das aktuelle Dokument hinaus nicht.
Das gewünschte Ziel ist aber relativ einfach, wenn auch nicht gerade elegant, über ein mit Hilfe des Makro-Rekorders zusammengesetzen Code erreichbar:
Code: Alles auswählen
sub ClipboardCopy
dim document as object, dispatcher as object, myDoc as Object, newdoc as Object
dim Dummy()
'get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
'hier muß die Quell-Range eingegeben werden
args1(0).Value = "$A$1:$E$10"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
'Jetzt wird das neue Dokument geladen
myDoc = StarDesktop.loadComponentFromURL("file:///DerPfadzurneuenDatei" , "_blank", 0, Dummy() )
newdoc = myDoc.getCurrentController.Frame
'Jetzt geht das Pasten los
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
'Hier muß die Ziel Range rein)
args2(0).Value = "$A$1:$E$10"
dispatcher.executeDispatch(newdoc, ".uno:GoToCell", "", 0, args2())
dispatcher.executeDispatch(newdoc, ".uno:Paste", "", 0, Array())
end sub
Dinge, die noch individuell anzupassen sind, habe ich eingerückt geschrieben. Hoffe, es hilft!
Viele Grüße,
Vanished