Where is the OO basic method to do the same as the "move/copy sheet" GUI action. I've been poking around the API documentation but can't find it.
Peter
Calc: move/copy sheet - where is it?
Calc: move/copy sheet - where is it?
Peter
OO 4.1.1 on MS Windows 7 64-bit
OO 4.1.1 on MS Windows 7 64-bit
- kingfisher
- Volunteer
- Posts: 2127
- Joined: Tue Nov 20, 2007 10:53 am
Re: Calc: move/copy sheet - where is it?
The methods belong to 'Sheets':
ThisComponent.Sheets.copybyName | movebyName
ThisComponent.Sheets.copybyName | movebyName
Apache OpenOffice 4.1.12 on Linux
Re: Calc: move/copy sheet - where is it?
Yep, interface com.sun.star.sheet.XSpreadsheets provides the methods to insert, copy and move a sheet within the same collection of sheets.
The following proposal copies from one document to another. The source document needs to be stored to disk. May be there is a workaround for unsaved documents. I don't know.
Copied references to other sheets behave analog to the discussion with huw in [Tutorial] Absolute, relative and mixed references
The following proposal copies from one document to another. The source document needs to be stored to disk. May be there is a workaround for unsaved documents. I don't know.
Code: Select all
REM ***** BASIC *****
REM copy first sheet of this document to position 2 of a new one
Sub Main
REM source document
Dim sURL$, sLinkSheetName$
sURL = thisComponent.getURL()
sLinkSheetName = thisComponent.Sheets.getByIndex(0).getName()
REM target document
Dim doc, sheets, sName$, pos%
doc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_default",0, Array())
sheets = doc.getSheets()
sName = getUniqueName(sheets, "Copied")
pos = 1
REM new sheet
Dim sh
sheets.insertNewByName(sName, pos)
sh = sheets.getByName(sName)
REM link the new sheet
sh.link(sURL, sLinkSheetName, "calc8", "", com.sun.star.sheet.SheetLinkMode.NORMAL)
REM break link
sh.setLinkMode(com.sun.star.sheet.SheetLinkMode.NONE)
End Sub
Function getUniqueName(oContainer,sName$)
Dim i%,sNew$
sNew = sName
Do while oContainer.hasByName(sNew)
i = i +1
sNew = sName &"_"& i
loop
getUniqueName = sNew
End Function
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
[SOLVED] Calc: move/copy sheet - where is it?
Thanks Villeroy. I should have said that source and destination are in different documents, but you seem to have guessed.
It seems a bit long-winded and not very intuitive - is that how the move/copy feature works in the GUI do you know?
It seems a bit long-winded and not very intuitive - is that how the move/copy feature works in the GUI do you know?
Peter
OO 4.1.1 on MS Windows 7 64-bit
OO 4.1.1 on MS Windows 7 64-bit
Re: Calc: move/copy sheet - where is it?
Get used to play on the naked bones of the API. Quite often you have to find your own technique to get the right sound.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Calc: move/copy sheet - where is it?
Hi everyone,
I used the code from the Villeroy code.And Everything works fine except that I can't export an image from the source document to the target document..What is wrong?Or is it possible to do such thing?
Casue when I use it manually from the calc (without macro thing), by this follow instructions -- right click on a sheet tabs -- >choose copy/move ---> choose a new workbook-->click ok, then all the items (including an object or image) in the source document are being move/copy to the target document....
Does anyone have a solution of my problem??
I used the code from the Villeroy code.And Everything works fine except that I can't export an image from the source document to the target document..What is wrong?Or is it possible to do such thing?
Casue when I use it manually from the calc (without macro thing), by this follow instructions -- right click on a sheet tabs -- >choose copy/move ---> choose a new workbook-->click ok, then all the items (including an object or image) in the source document are being move/copy to the target document....
Does anyone have a solution of my problem??
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
-
- Posts: 56
- Joined: Thu Apr 22, 2010 5:03 am
Re: Calc: move/copy sheet - where is it?
You can test EasyDev, you can help me validate this function.
https://github.com/UniversoLibreMexicoA ... v2.3.0.oxt
http://easydev.readthedocs.org/en/lates ... o-document
Best regards
https://github.com/UniversoLibreMexicoA ... v2.3.0.oxt
http://easydev.readthedocs.org/en/lates ... o-document
Code: Select all
Sub CopySheets()
util = createUnoService("org.universolibre.EasyDev")
source = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")
target = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")
doc = ThisComponent
source.Doc = doc
new_doc = util.newDoc("")
target.Doc = new_doc
util.sheetCopyToDoc(source, target, -1, True, True)
End Sub
______________________________________________
Everything not given is lost
AOO 4.1 / LibO 4.3 on ArchLinux with Gnome3
Please, I do not answer private questions, you use the forum
Everything not given is lost
AOO 4.1 / LibO 4.3 on ArchLinux with Gnome3
Please, I do not answer private questions, you use the forum
Re: Calc: move/copy sheet - where is it?
mauriciobaeza wrote:You can test EasyDev, you can help me validate this function.
https://github.com/UniversoLibreMexicoA ... v2.3.0.oxt
http://easydev.readthedocs.org/en/lates ... o-documentBest regardsCode: Select all
Sub CopySheets() util = createUnoService("org.universolibre.EasyDev") source = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") target = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") doc = ThisComponent source.Doc = doc new_doc = util.newDoc("") target.Doc = new_doc util.sheetCopyToDoc(source, target, -1, True, True) End Sub
Okay tks for the code mauriciobaeza
You are my hero
Debian 8 Jessie
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need
Linux Mint 17.3 XFCE
Country : Indonesia
Learning is a need