 | OO-Snippets: Copy all cells from one to another sheetCommons| Keywords | copy, sheet, another, document, clipboard, paste |
|---|
| Language | OOBasic |
|---|
| Application | Calc |
|---|
| Authors | Stephan Wunderlich (initial)
Michael Hoennig (initial)
Tom Schindl
|
|---|
| Supported Versions | 1.1.4 1.1.x |
|---|
| Supported OS | All |
|---|
| Question |
How copy a sheet to another calc document?
|
|---|
| Answer |
The following macro copies the contents of a given sheet into a newly created of a second document:
|
|---|
Sub Main
firstDoc = ThisComponent
selectSheetByName(firstDoc, "Sheet2")
dispatchURL(firstDoc,".uno:SelectAll")
dispatchURL(firstDoc,".uno:Copy")
secondDoc = StarDesktop.loadComponentFromUrl("private:factory/scalc","_blank",0,dimArray())
secondDoc.getSheets().insertNewByName("inserted",0)
selectSheetByName(secondDoc, "inserted")
dispatchURL(secondDoc,".uno:Paste")
End Sub
sub selectSheetByName(document, sheetName)
document.getCurrentController.select(document.getSheets().getByName(sheetName))
end sub
Sub dispatchURL(document, aURL)
Dim noProps()
Dim URL as new com.sun.star.util.URL
frame = document.getCurrentController().getFrame()
URL.Complete = aURL
transf = createUnoService("com.sun.star.util.URLTransformer")
transf.parseStrict(URL)
disp = frame.queryDispatch(URL, "", com.sun.star.frame.FrameSearchFlag.SELF OR com.sun.star.frame.FrameSearchFlag.CHILDREN)
disp.dispatch(URL, noProps())
End Sub
|
Changelog| Date | User | Modification |
|---|
| 2005-03-17 | tomsontom | Fixed bug of wrong line break. Added OS-Info, OO-Info and IDL-Linking | | 2004-06-22 | tomsontom | Modified to match new snippet-DTD | | 0000-00-00 | ste | initial release |
|