OO-Snippets: copySheet

Commons

Keywords
LanguageooRexx
ApplicationCalc
AuthorsMichael Hinz (initial)
Supported Versions2.0.x  
Supported OSWin32  
QuestionHow to copy a sheet
Answer

Code-Snippet-Listing (snippet-source)

/* get the dsktop (an Xdesctop object) */
oDesktop         = UNO.createDesktop()   
xComponentLoader = oDesktop~XDesktop~XComponentLoader      -- get componentLoader interface
                                                      

/* open the file: test.ods  */
url = ConvertToURL(directory()"/test.ods")
xCalcComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)

/* get  sheet â~@~^Rexxâ~@~\ in spreadsheet */
xDocument = xCalcComponent~XSpreadSheetDocument
xSheet = xDocument~getSheets~XNameAccess~getByName("Rexx")~XSpreadSheet

/* insert  values into cells */
CALL UNO.setCell xSheet, 0, 0, "This sheet will be copied"
CALL UNO.setCell xSheet, 0, 1, "333"
CALL UNO.setCell xSheet, 0, 2, "222"
CALL UNO.setCell xSheet, 0, 3, "111"

CALL syssleep 3

/* copy sheet */
xSheets = xDocument~getSheets()
xSheets~copyByName("Rexx", "rexx2", 2)

/* set focus on new sheet */
xFocusSheet = xDocument~getSheets~XNameAccess~getByName("rexx2")~XSpreadSheet
xController = xDocument~XModel~getCurrentController
xSpreadsheetView = xController~xSpreadsheetView~setActiveSheet(xFocusSheet)


::requires UNO.cls       -- get UNO support

Changelog

DateUserModification

and