Difference between revisions of "Documentation/DevGuide/Database/Forms and Reports"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 8: Line 8:
 
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Database/{{SUBPAGENAME}}}}  
 
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Database/{{SUBPAGENAME}}}}  
 
  {{DISPLAYTITLE:Forms and Reports}}
 
  {{DISPLAYTITLE:Forms and Reports}}
Since {{PRODUCTNAME}} {{OO2.0.0}}, you can not only link to documents that belong to a data source, but you can store your forms and reports within the Open Office database file.
+
Since OpenOffice.org 2.0.0, you can not only link to documents that belong to a data source, but you can store your forms and reports within the OpenOffice database file.
  
 
<!--<idltopic>com.sun.star.sdb.XFormDocumentsSupplier</idltopic>-->
 
<!--<idltopic>com.sun.star.sdb.XFormDocumentsSupplier</idltopic>-->
 
The interface <idl>com.sun.star.sdb.XFormDocumentsSupplier</idl>, supplied by the <idls>com.sun.star.sdb.DataSource</idls>, provides access to the forms stored in the database file of the data source. It has one method:
 
The interface <idl>com.sun.star.sdb.XFormDocumentsSupplier</idl>, supplied by the <idls>com.sun.star.sdb.DataSource</idls>, provides access to the forms stored in the database file of the data source. It has one method:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   com::sun::star::container::XNameAccess getFormDocuments()
 
   com::sun::star::container::XNameAccess getFormDocuments()
</source>
+
</syntaxhighlight>
 
<!--<idltopic>com.sun.star.sdb.XReportDocumentsSupplier</idltopic>-->
 
<!--<idltopic>com.sun.star.sdb.XReportDocumentsSupplier</idltopic>-->
 
The interface <idl>com.sun.star.sdb.XReportDocumentsSupplier</idl> provides access to the reports stored in the database file of the data source. It has one method:
 
The interface <idl>com.sun.star.sdb.XReportDocumentsSupplier</idl> provides access to the reports stored in the database file of the data source. It has one method:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   com::sun::star::container::XNameAccess getReportDocuments()
 
   com::sun::star::container::XNameAccess getReportDocuments()
</source>
+
</syntaxhighlight>
 
The returned service is a <idl>com.sun.star.sdb.DocumentContainer</idl>. The <code>DocumentContainer</code> is not only an <code>XNameAccess</code>, but a <idl>com.sun.star.container.XNameContainer</idl>, which means that new forms or reports are added using <code>insertByName()</code> as described in the [[Documentation/DevGuide/FirstSteps/First Steps|First Steps]] chapter. To support the creation of hierarchies, the service <idl>com.sun.star.sdb.DocumentContainer</idl> additionally supplies the interfaces <idl>com.sun.star.container.XHierarchicalNameContainer</idl> and <idl>com.sun.star.container.XHierarchicalNameAccess</idl>. The interfaces <idl>com.sun.star.container.XHierarchicalNameContainer</idl> and <idl>com.sun.star.container.XHierarchicalNameAccess</idl> can be used to create folder hierarchies and to organize forms or reports in different sub folders.
 
The returned service is a <idl>com.sun.star.sdb.DocumentContainer</idl>. The <code>DocumentContainer</code> is not only an <code>XNameAccess</code>, but a <idl>com.sun.star.container.XNameContainer</idl>, which means that new forms or reports are added using <code>insertByName()</code> as described in the [[Documentation/DevGuide/FirstSteps/First Steps|First Steps]] chapter. To support the creation of hierarchies, the service <idl>com.sun.star.sdb.DocumentContainer</idl> additionally supplies the interfaces <idl>com.sun.star.container.XHierarchicalNameContainer</idl> and <idl>com.sun.star.container.XHierarchicalNameAccess</idl>. The interfaces <idl>com.sun.star.container.XHierarchicalNameContainer</idl> and <idl>com.sun.star.container.XHierarchicalNameAccess</idl> can be used to create folder hierarchies and to organize forms or reports in different sub folders.
  
Line 77: Line 77:
  
 
The service <idl>com.sun.star.sdb.DocumentContainer</idl> additionally defines the interface <idl>com.sun.star.frame.XComponentLoader</idl> that is used to get access to the contained document inside the <code>DocumentDefinition</code> and it has one method:
 
The service <idl>com.sun.star.sdb.DocumentContainer</idl> additionally defines the interface <idl>com.sun.star.frame.XComponentLoader</idl> that is used to get access to the contained document inside the <code>DocumentDefinition</code> and it has one method:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   com::sun::star::lang::XComponent loadComponentFromURL(
 
   com::sun::star::lang::XComponent loadComponentFromURL(
 
           [in] string URL,
 
           [in] string URL,
Line 86: Line 86:
 
                   com::sun::star::lang::IllegalArgumentException );
 
                   com::sun::star::lang::IllegalArgumentException );
  
</source>
+
</syntaxhighlight>
 
* URL: describes the name of the document definition to load,
 
* URL: describes the name of the document definition to load,
 
* TargetFrameName: is not used.
 
* TargetFrameName: is not used.
Line 93: Line 93:
 
*# PropertyValue
 
*# PropertyValue
 
*#* Name = ActiveConnection
 
*#* Name = ActiveConnection
*#* Value = [IDL:com.sun.star.sdbc.XConnection] The connection that is used when opening the text document.
+
*#* Value = <idl>com.sun.star.sdbc.XConnection</idl> The connection that is used when opening the text document.
 
*# PropertyValue
 
*# PropertyValue
 
*#* Name = OpenMode
 
*#* Name = OpenMode
 
*#* Value = string, "open" if the document is to be opened in live mode (editing is not possible), "openDesign" if the document is to be opened in design mode (editing is possible)
 
*#* Value = string, "open" if the document is to be opened in live mode (editing is not possible), "openDesign" if the document is to be opened in design mode (editing is possible)
<source lang="java">
+
<syntaxhighlight lang="java">
 
   // opens a form in design mode
 
   // opens a form in design mode
 
       public static void openFormInDesignMode(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception
 
       public static void openFormInDesignMode(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception
Line 120: Line 120:
 
           }
 
           }
 
       }
 
       }
</source>
+
</syntaxhighlight>
 
The returned object is a <idl>com.sun.star.text.TextDocument</idl> service. For forms, see [[Documentation/DevGuide/Forms/Forms|Forms]]
 
The returned object is a <idl>com.sun.star.text.TextDocument</idl> service. For forms, see [[Documentation/DevGuide/Forms/Forms|Forms]]
  

Revision as of 13:50, 21 December 2020



Since OpenOffice.org 2.0.0, you can not only link to documents that belong to a data source, but you can store your forms and reports within the OpenOffice database file.

The interface com.sun.star.sdb.XFormDocumentsSupplier, supplied by the DataSource, provides access to the forms stored in the database file of the data source. It has one method:

  com::sun::star::container::XNameAccess getFormDocuments()

The interface com.sun.star.sdb.XReportDocumentsSupplier provides access to the reports stored in the database file of the data source. It has one method:

  com::sun::star::container::XNameAccess getReportDocuments()

The returned service is a com.sun.star.sdb.DocumentContainer. The DocumentContainer is not only an XNameAccess, but a com.sun.star.container.XNameContainer, which means that new forms or reports are added using insertByName() as described in the First Steps chapter. To support the creation of hierarchies, the service com.sun.star.sdb.DocumentContainer additionally supplies the interfaces com.sun.star.container.XHierarchicalNameContainer and com.sun.star.container.XHierarchicalNameAccess. The interfaces com.sun.star.container.XHierarchicalNameContainer and com.sun.star.container.XHierarchicalNameAccess can be used to create folder hierarchies and to organize forms or reports in different sub folders.

Along with the name access, forms and reports are obtained through com.sun.star.container.XIndexAccess, and com.sun.star.container.XEnumerationAccess.

The interface com.sun.star.lang.XMultiServiceFactory is used to create new forms or reports. The method createInstanceWithArguments() of XMultiServiceFactory creates a new document definition. Whether the document is a form or a report depends on the container where this object is inserted.

Relation design of Reports and Forms

The following are the allowed properties for the document definition:

Arguments of createInstanceWithArguments method with com.sun.star.sdb.DocumentDefinition as service name
PropertyValue Name: Name

Value: string - Defines the name of the document.

PropertyValue Name: URL

Value: string - Points to a extern document.

PropertyValue Name: ActiveConnection

Value: com.sun.star.sdbc.XConnection - The connection to be used by the document.

PropertyValue Name: EmbeddedObject

Value: com.sun.star.sdb.DocumentDefinition - The document definition that is to be copied.

To create a new document definition, only the Name and the ActiveConnection must be set. If an existing document from the file system is to be included, the URL property must be filled with the file URL. To copy document definitions, the EmbeddedObject must be filled with the document definition to be copied.

The following are the allowed properties for the document container:

Arguments of createInstanceWithArguments method with com.sun.star.sdb.Forms or com.sun.star.sdb.Reports as service name
PropertyValue Name: Name

Value: string - Defines the name of the document.

PropertyValue Name: EmbeddedObject

Value: com.sun.star.sdb.DocumentDefinition or com.sun.star.sdb.DocumentContainer - The document definition (form or report object) or a document container (form container or report container) which is to be copied.

When creating a sub folder inside the forms or reports hierarchy, it is enough to set the Name property. If the EmbeddedObject property is set, then it is copied. If the EmbeddedObject supports the XHierarchicalNameAccess, the children are also copied. The EmbeddedObject can be a document definition or a document container.

The service com.sun.star.sdb.DocumentContainer additionally defines the interface com.sun.star.frame.XComponentLoader that is used to get access to the contained document inside the DocumentDefinition and it has one method:

  com::sun::star::lang::XComponent loadComponentFromURL(
          [in] string URL,
          [in] string TargetFrameName,
          [in] long SearchFlags,
          [in] sequence<com::sun::star::beans::PropertyValue> Arguments)
          raises( com::sun::star::io::IOException,
                  com::sun::star::lang::IllegalArgumentException );
  • URL: describes the name of the document definition to load,
  • TargetFrameName: is not used.
  • SearchFlags: is not used.
  • Arguments:
    1. PropertyValue
    2. PropertyValue
      • Name = OpenMode
      • Value = string, "open" if the document is to be opened in live mode (editing is not possible), "openDesign" if the document is to be opened in design mode (editing is possible)
  // opens a form in design mode
      public static void openFormInDesignMode(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception
      {
          XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class,
          _rMSF.createInstance("com.sun.star.sdb.DatabaseContext"));
          // we use the first datasource
          XDataSource xDS = (XDataSource)UnoRuntime.queryInterface(
          XDataSource.class, xNameAccess.getByName( "Bibliography" )); 
          XConnection con = xDS.getConnection("","");
          XFormsSupplier xSup = (XFormsSupplier)UnoRuntime.queryInterface(XFormsSupplier.class, xDS); 
 
          XNameAccess xForms = xSup.getFormDocuments();
          if ( xForms.hasByName("Form1") ){
              Object form = xForms.getByName("Form1"); // to hold ref
              {
                  XComponentLoader loader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, xForms); 
                  PropertyValue[] args = new PropertyValue[]{PropertyValue("OpenMode",0,"openDesign")
                  ,PropertyValue("ActiveConnection",0,con)};
                  XComponent formdocument = loader.loadComponentFromURL("Form1","",0,args);
              }
          }
      }

The returned object is a com.sun.star.text.TextDocument service. For forms, see Forms

Documentation note.png The document definition object is the owner of the accessed com.sun.star.text.TextDocument. When the document definition is released (last reference gone), the text document is also closed.

The returned form or report documents are com.sun.star.sdb.DocumentDefinition services. These are the properties of the com.sun.star.sdb.DocumentDefinition service.

Properties of com.sun.star.sdb.DocumentDefinition
Name string - Defines the name of the document.
AsTemplate boolean - Indicates if the document is to be used as template, for example, if a report is to be filled with data.

In addition to these properties, the com.sun.star.sdb.DocumentDefinitionservice offers acom.sun.star.sdbcx.XRenameto rename a DocumentDefinition.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages