Difference between revisions of "Documentation/DevGuide/Spreadsheets/Database Import"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Documentation/Developers Guide/Spreadsheet Documents)
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/Spreadsheets/Database Ranges
 
|NextPage=Documentation/DevGuide/Spreadsheets/Database Ranges
 
}}
 
}}
{{DISPLAYTITLE:Database Import}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Database Import}}
 
<!--<idltopic>com.sun.star.sheet.DatabaseImportDescriptor</idltopic>-->
 
<!--<idltopic>com.sun.star.sheet.DatabaseImportDescriptor</idltopic>-->
The <idl>com.sun.star.util.XImportable</idl> interface imports data from an external data source (database) into spreadsheet cells. The database has to be registered in {{PRODUCTNAME}} API, so that it can be selected using its name. The <code>doImport</code> call takes a sequence of property values that select the data to import.
+
The <idl>com.sun.star.util.XImportable</idl> interface imports data from an external data source (database) into spreadsheet cells. The database has to be registered in {{AOo}} API, so that it can be selected using its name. The <code>doImport</code> 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 <code>createImportDescriptor()</code> method can be used and modified. The <code>createImportDescriptor()</code> method returns a description of the previously imported data if the cell range is a database range with stored import settings and the <code>bEmpty</code> parameter is <code>false</code>.
 
Similar to the sort descriptor, the import descriptor's sequence of property values can be constructed from scratch, or the return value of the <code>createImportDescriptor()</code> method can be used and modified. The <code>createImportDescriptor()</code> method returns a description of the previously imported data if the cell range is a database range with stored import settings and the <code>bEmpty</code> parameter is <code>false</code>.
Line 22: Line 23:
 
If a database name is in the <code>aDatabase</code> variable and a table name in <code>aTableName</code>, the following code imports that table from the database:  
 
If a database name is in the <code>aDatabase</code> variable and a table name in <code>aTableName</code>, the following code imports that table from the database:  
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
 
+
<syntaxhighlight lang="java">
 
   // --- import from database ---
 
   // --- import from database ---
 
   com.sun.star.beans.PropertyValue[] aImportDesc = new com.sun.star.beans.PropertyValue[3];
 
   com.sun.star.beans.PropertyValue[] aImportDesc = new com.sun.star.beans.PropertyValue[3];
Line 38: Line 39:
 
       UnoRuntime.queryInterface(com.sun.star.util.XImportable.class, xImportRange);
 
       UnoRuntime.queryInterface(com.sun.star.util.XImportable.class, xImportRange);
 
   xImport.doImport(aImportDesc);
 
   xImport.doImport(aImportDesc);
 
+
</syntaxhighlight>
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]

Latest revision as of 15:51, 3 January 2021



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 Apache OpenOffice 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.

DatabaseImportDescriptor

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 is TABLE, the whole table that is named by SourceObject is imported.
  • If SourceType is QUERY, the SourceObject must be the name of a named query.
  • If SourceType is SQL, the SourceObject 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).
Personal tools
In other languages