blob: ad08abdc5897391b8913e540c09ab88cb56428e0 [file] [log] [blame]
<?xml version="1.0"?>
<!--
$RCSfile: Calc.DatabaseContent.snip,v $
last change: $Revision: 1.1 $ $Author: tomsontom $ $Date: 2006/07/14 09:36:42 $
(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.
Public Documentation License Notice:
The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html
The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.
The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.
The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.
All Rights Reserved.
-->
<snippet language="ooRexx" application="Calc">
<keywords>
</keywords>
<authors>
<author id="" initial="true" email="h0253952@wu-wien.ac.at">Michael Hinz</author>
</authors>
<question heading="DatabaseContent">How can i import data from a database
</question>
<answer>
<p>first you have to register the database in OOo. This is done by clicking: New &gt;&gt; Database &gt;&gt; add existing database</p>
<listing>/* get the desktop (an Xdesktop object) */
oDesktop = UNO.createDesktop()
xComponentLoader = oDesktop~{%see com.sun.star.frame.XDesktop%XDesktop}~{%see com.sun.star.frame.XComponentLoader%XComponentLoader} --get componentLoader interface
/* open a blank calc file */
url = &quot;private:factory/scalc&quot;
xCalcComponent = xComponentLoader~loadComponentFromURL(url, &quot;_blank&quot;, 0, .UNO~noProps)
/* get first sheet in spreadsheet */
xDocument = xCalcComponent~{%see com.sun.star.sheet.XSpreadsheetDocument%XSpreadSheetDocument}
xSheet = xDocument~getSheets~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getByIndex(0)~{%see com.sun.star.sheet.XSpreadsheet%XSpreadSheet}
/*set values for importing into an array*/
importDesc = bsf.createArray(.UNO~propertyValue, 3)
importDesc[1] = .UNO~propertyValue~new
importDesc[1]~Name = &quot;DatabaseName&quot;
importDesc[1]~Value = &quot;rexx&quot;
importDesc[2] = .UNO~propertyValue~new
importDesc[2]~Name = &quot;SourceType&quot;
importDesc[2]~Value = bsf.getConstant(&quot;{%see com.sun.star.sheet.DataImportMode}&quot;,&quot;TABLE&quot;)
importDesc[3] = .UNO~propertyValue~new
importDesc[3]~Name = &quot;SourceObject&quot;
importDesc[3]~Value = CD
xImport = xSheet~getCellRangeByName(&quot;A1:A1&quot;)
myImport = xImport~{%see com.sun.star.util.XImportable%XImportable} -- call interface XImportable
myImport~doImport(importDesc) -- import data
::requires UNO.CLS -- get UNO support
</listing>
</answer>
<versions>
<version number="2.0.x" status="tested"/>
</versions>
<operating-systems>
<operating-system name="Win32"/>
</operating-systems>
<changelog>
</changelog>
</snippet>