Database Import
The com.sun.star.util.XImportable interface imports data from an external data source (database) into spreadsheet cells. The database has to be registered in OpenOffice.org API, so that it can be selected using its name. The doImport
call takes a sequence of property values that select the data to import.
Similar to the sort descriptor, the import descriptor's sequence of property values can be constructed from scratch, or the return value of the createImportDescriptor()
method can be used and modified. The createImportDescriptor()
method returns a description of the previously imported data if the cell range is a database range with stored import settings and the bEmpty
parameter is false
.
The DatabaseName
property selects a database. The SourceType
selects the kind of object from the database that is imported. It can have the following values:
- If
SourceType
isTABLE
, the whole table that is named bySourceObject
is imported. - If
SourceType
isQUERY
, theSourceObject
must be the name of a named query. - If
SourceType
isSQL
, theSourceObject
is used as a literal SQL command string.
If a database name is in the aDatabase
variable and a table name in aTableName
, the following code imports that table from the database:
// --- import from database --- com.sun.star.beans.PropertyValue[] aImportDesc = new com.sun.star.beans.PropertyValue[3]; aImportDesc[0] = new com.sun.star.beans.PropertyValue(); aImportDesc[0].Name = "DatabaseName"; aImportDesc[0].Value = aDatabase; aImportDesc[1] = new com.sun.star.beans.PropertyValue(); aImportDesc[1].Name = "SourceType"; aImportDesc[1].Value = com.sun.star.sheet.DataImportMode.TABLE; aImportDesc[2] = new com.sun.star.beans.PropertyValue(); aImportDesc[2].Name = "SourceObject"; aImportDesc[2].Value = aTableName; com.sun.star.table.XCellRange xImportRange = xSheet.getCellRangeByName("B33:B33"); com.sun.star.util.XImportable xImport = ( com.sun.star.util.XImportable ) UnoRuntime.queryInterface(com.sun.star.util.XImportable.class, xImportRange); xImport.doImport(aImportDesc);
Content on this page is licensed under the Public Documentation License (PDL). |