OO-Snippets: DatabaseContent

Commons

Keywords
LanguageooRexx
ApplicationCalc
AuthorsMichael Hinz (initial)
Supported Versions2.0.x  
Supported OSWin32  
QuestionHow can i import data from a database
Answer

first you have to register the database in OOo. This is done by clicking: New >> Database >> add existing database

Code-Snippet-Listing (snippet-source)

/* get the desktop  (an Xdesktop object) */
oDesktop = UNO.createDesktop()   
xComponentLoader = oDesktop~XDesktop~XComponentLoader      --get componentLoader interface
                                                      
/* open a blank calc file */
url = "private:factory/scalc"
xCalcComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)


/* get first sheet in spreadsheet */
xDocument = xCalcComponent~XSpreadSheetDocument
xSheet = xDocument~getSheets~XIndexAccess~getByIndex(0)~XSpreadSheet

/*set values for importing into an array*/
    importDesc = bsf.createArray(.UNO~propertyValue, 3)

importDesc[1] = .UNO~propertyValue~new
    importDesc[1]~Name  = "DatabaseName"
    importDesc[1]~Value = "rexx"
	
importDesc[2] = .UNO~propertyValue~new    
    importDesc[2]~Name  = "SourceType"
    importDesc[2]~Value = bsf.getConstant("com.sun.star.sheet.DataImportMode","TABLE")

importDesc[3] = .UNO~propertyValue~new
    importDesc[3]~Name  = "SourceObject"
    importDesc[3]~Value = CD
    
xImport = xSheet~getCellRangeByName("A1:A1")
myImport = xImport~XImportable                                    -- call interface XImportable
myImport~doImport(importDesc)                                    -- import data

::requires UNO.CLS       -- get UNO support

Changelog

DateUserModification

and